rabin 7 years ago
commit
edb52b4f95
7 changed files with 612 additions and 0 deletions
  1. 14 0
      LICENSE
  2. 2 0
      README.md
  3. 189 0
      database/inbox.php
  4. 125 0
      database/outbox.php
  5. 98 0
      database/type.php
  6. 7 0
      index.php
  7. 177 0
      src/Data.php

+ 14 - 0
LICENSE

@@ -0,0 +1,14 @@
+Apache License
+Copyright 2016-2017 Dever(dever.cc)
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.

+ 2 - 0
README.md

@@ -0,0 +1,2 @@
+# message
+

+ 189 - 0
database/inbox.php

@@ -0,0 +1,189 @@
+<?php
+
+# 定义几个常用的选项
+$option = array
+(
+	1 => '显示',
+	2 => '不显示',
+);
+
+$status = array
+(
+	1 => '未读',
+	2 => '已读',
+);
+
+$type = function()
+{
+	return Dever::load('message/type-all');
+};
+
+return array
+(
+	# 表名
+	'name' => 'inbox',
+	# 显示给用户看的名称
+	'lang' => '收件箱',
+	'order' => 18,
+	'menu'	=> false,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'fulltext',
+			'order'		=> 'desc',
+			'list'		=> true,
+		),
+
+		'oid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '收件id',
+			'default' 	=> '',
+			'desc' 		=> '请填写收件id',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			//'list'		=> true,
+		),
+
+		'uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '收件人',
+			'default' 	=> '',
+			'desc' 		=> '请填写收件人',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			//'list'		=> true,
+		),
+
+		'from_uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '发件人',
+			'default' 	=> '',
+			'desc' 		=> '请填写发件人',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			//'list'		=> true,
+		),
+
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-30',
+			'name' 		=> '发件标题',
+			'default' 	=> '',
+			'desc' 		=> '请填写发件标题',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			//'list'		=> true,
+		),
+
+		'content'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '发件内容',
+			'default' 	=> '',
+			'desc' 		=> '请填写发件内容',
+			'match' 	=> 'is_string',
+			'update'	=> 'textarea',
+			//'list'		=> true,
+		),
+
+		'type'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '消息类型',
+			'default' 	=> '1',
+			'desc' 		=> '消息类型',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $type,
+			'update'	=> 'select',
+			//'search'	=> 'select',
+			//'list'		=> true,
+		),
+
+		'status'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '已读状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $status,
+			'update'	=> 'radio',
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $option,
+			'update'	=> 'radio',
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			//'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	'manage' => array
+	(
+
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		# 获取列表页
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				//'name' => array('yes', 'like'),
+				'uid' => 'yes',
+				'status' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'page' => array(12, 'list'),
+			'order' => array('id' => 'desc'),
+			'col' => '*',
+		),
+		# 获取未读消息
+		'getInfo' => array
+		(
+			# 匹配的正则或函数 选填项
+			'where' => array
+			(
+				'uid' => 'yes',
+				'status' => 'yes',
+				'type' => 'yes'
+			),
+			'type' => 'all',
+			'order' => array('id' => 'desc'),
+			'col' => '*',
+		),
+	),
+);

+ 125 - 0
database/outbox.php

@@ -0,0 +1,125 @@
+<?php
+
+# 定义几个常用的选项
+$option = array
+(
+	1 => '显示',
+	2 => '不显示',
+);
+
+/*
+$type = function()
+{
+	return Dever::load('message/type-all');
+};
+*/
+$type = array
+(
+	1 => '系统消息',
+);
+
+return array
+(
+	# 表名
+	'name' => 'outbox',
+	# 显示给用户看的名称
+	'lang' => '发件箱',
+	'order' => 19,
+	//'menu'	=> false,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'fulltext',
+			'order'		=> 'desc',
+			'list'		=> true,
+		),
+
+		'uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '发件人',
+			'default' 	=> '-1',
+			'desc' 		=> '请填写发件人',
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'text',
+			//'list'		=> true,
+		),
+
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-30',
+			'name' 		=> '发件标题',
+			'default' 	=> '',
+			'desc' 		=> '请填写发件标题',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'content'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '发件内容',
+			'default' 	=> '',
+			'desc' 		=> '请填写发件内容',
+			'match' 	=> 'is_string',
+			'update'	=> 'textarea',
+			'list'		=> true,
+		),
+
+		'type'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '消息类型',
+			'default' 	=> '1',
+			'desc' 		=> '消息类型',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $type,
+			'update'	=> 'select',
+			//'search'	=> 'select',
+			//'list'		=> true,
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $option,
+			'update'	=> 'radio',
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			//'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+	
+	'manage' => array
+	(
+		
+	),
+	
+	# request 请求接口定义
+	'request' => array
+	(
+		
+	),
+);

+ 98 - 0
database/type.php

@@ -0,0 +1,98 @@
+<?php
+
+# 定义几个常用的选项
+$option = array
+(
+	1 => '显示',
+	2 => '不显示',
+);
+
+$type = array
+(
+	1 => '不发送push',
+	2 => '发送push',
+);
+
+return array
+(
+	# 表名
+	'name' => 'type',
+	# 显示给用户看的名称
+	'lang' => '消息类型',
+	'order' => 20,
+	'menu' => false,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'fulltext',
+			'order'		=> 'desc',
+			'list'		=> true,
+		),
+
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-30',
+			'name' 		=> '类型名称-类型id值为10以下则为系统消息',
+			'default' 	=> '',
+			'desc' 		=> '请填写类型名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			//'list'		=> true,
+		),
+
+		'type'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '是否同时发送push',
+			'default' 	=> '1',
+			'desc' 		=> '请选择是否同时发送push',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $type,
+			'update'	=> 'radio',
+			//'search'	=> 'select',
+			//'list'		=> true,
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $option,
+			'update'	=> 'radio',
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			//'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+	
+	'manage' => array
+	(
+		
+	),
+	
+	# request 请求接口定义
+	'request' => array
+	(
+		
+	),
+);

+ 7 - 0
index.php

@@ -0,0 +1,7 @@
+<?php
+define('DEVER_APP_NAME', 'message');
+define('DEVER_APP_LANG', '消息系统');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', -6);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-dashboard');
+include(DEVER_APP_PATH . '../boot.php');

+ 177 - 0
src/Data.php

@@ -0,0 +1,177 @@
+<?php
+
+namespace Message\Src;
+
+use Dever;
+
+class Data
+{
+	public function __construct()
+	{
+		$this->uid = intval(Dever::input('uid', 0));
+
+		if (!$this->uid || $this->uid < 0) {
+			Dever::alert('错误的用户信息');
+		}
+        parent::__construct();
+	}
+
+	/**
+     * 获取我的消息
+     * 
+     * @return mixed
+     */
+	public function read()
+	{
+		$uid = $this->uid;
+
+		$prefix = defined('DEVER_PROJECT') && DEVER_PROJECT != 'default' ? DEVER_PROJECT . '_' : '';
+		$outbox = $prefix . 'message_outbox';
+		$inbox = $prefix . 'message_inbox';
+
+		$where = ' and a.state = 1';
+		# 读取outbox里的数据
+		$sql = 'select a.name,a.content,a.id,a.type,a.uid 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_type'] = $v['type'];
+				//$insert['add_site'] = $v['site'];
+				$insert['add_from_uid'] = $v['uid'];
+				$insert['add_name'] = $v['name'];
+				$insert['add_content'] = $v['content'];
+                Dever::load('message/inbox-insert', $insert);
+            }
+		}
+
+        $status = Dever::input('status', false);
+
+        $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);
+
+		return $data;
+	}
+
+    /**
+     * 查看我的新消息
+     * 
+     * @return mixed
+     */
+    public function num()
+    {
+        Dever::setInput('status', 1);
+        return $this->read();
+    }
+
+	/**
+     * 查看我的消息
+     * 
+     * @return mixed
+     */
+	public function view()
+	{
+		$id = Dever::input('message_id');
+
+		if ($id > 0) {
+			$info = Dever::load('message/inbox-one', array('option_uid' => $this->uid, 'option_id' => $id));
+			if ($info) {
+				Dever::load('message/inbox-update', array('where_id' => $id, 'set_status' => 2));
+
+				$data = Dever::load('message/inbox-check', $id);
+
+				return $data;
+			}
+		}
+
+		Dever::alert('错误的消息信息');
+	}
+
+	/**
+     * 推送消息
+     * 
+     * @return mixed
+     */
+	public function push()
+	{
+		$uid 		= $this->uid;
+        $name 		= Dever::input('name');
+        $content 	= Dever::input('content');
+        $type 	    = intval(Dever::input('type'));
+        # 暂时都是系统消息
+        $type 		= 1;
+        //$site 	    = intval(Dever::input('site', -1));
+        $to_uid 	= Dever::input('to_uid');
+
+        if (!is_numeric($type)) {
+            Dever::alert('错误的消息类型');
+        }
+        /*
+        if(!is_numeric($site))
+        {
+            Dever::alert('错误的站点ID');
+        }
+        */
+        if ($type > 10 && !is_numeric($uid)) {
+            Dever::alert('错误的发件人id');
+        }
+        if ($type > 10 && !$to_uid) {
+           	Dever::alert('错误的收件人id');
+        }
+        if (!$content) {
+            Dever::alert('错误的消息内容');
+        }
+
+        if (is_numeric($uid) && $content && is_numeric($type)) {
+        	if ($type < 10) {
+                $uid = -1;
+            }
+
+            $data['add_uid'] = $uid;
+            $data['add_name'] = $name;
+            $data['add_content'] = $content;
+            $data['add_type'] = $type;
+            //$data['add_site'] = $site;
+            $id = Dever::load('message/outbox-insert', $data);
+
+            if ($id > 0) {
+            	if ($to_uid) {
+                    $to_uid = explode(',', $to_uid);
+                    foreach ($to_uid as $k => $v) {
+                    	$info = Dever::load('message/outbox-one', array('option_uid' => $v, 'option_oid' => $id));
+                    	if ($info) {
+                    		$update['where_id'] = $info['id'];
+	                        $update['set_from_uid'] = $data['add_uid'];
+	                        $update['set_name'] = $data['add_name'];
+	                        $update['set_content'] = $data['add_content'];
+	                        //$update['origin'] = $origin;
+                    		Dever::load('message/inbox-update', $update);
+                    	} else {
+                    		$insert['add_uid'] = $v;
+	                        $insert['add_oid'] = $id;
+	                        $insert['add_status'] = 1;
+	                        $insert['add_type'] = $data['add_type'];
+	                        //$insert['add_site'] = $site;
+	                        $insert['add_from_uid'] = $data['add_uid'];
+	                        $insert['add_name'] = $data['add_name'];
+	                        $insert['add_content'] = $data['add_content'];
+	                        //$insert['add_origin'] = $origin;
+                    		Dever::load('message/inbox-insert', $insert);
+                    	}
+
+                    	//这里可以设置发送push
+                    }
+                }
+            }
+        }
+	}
+}