dever 7 gadi atpakaļ
vecāks
revīzija
b477924f8a
4 mainītis faili ar 216 papildinājumiem un 38 dzēšanām
  1. 18 13
      database/inbox.php
  2. 7 7
      database/outbox.php
  3. 17 18
      database/type.php
  4. 174 0
      lib/Data.php

+ 18 - 13
database/inbox.php

@@ -15,7 +15,7 @@ $status = array
 
 $type = function()
 {
-	return Dever::load('message/type-all');
+	return Dever::load('message/type-state');
 };
 
 return array
@@ -25,7 +25,6 @@ return array
 	# 显示给用户看的名称
 	'lang' => '收件箱',
 	'order' => 18,
-	'menu'	=> false,
 	# 数据结构
 	'struct' => array
 	(
@@ -36,7 +35,6 @@ return array
 			'default' 	=> '',
 			'desc' 		=> '',
 			'match' 	=> 'is_numeric',
-			'search'	=> 'fulltext',
 			'order'		=> 'desc',
 			'list'		=> true,
 		),
@@ -59,8 +57,9 @@ return array
 			'default' 	=> '',
 			'desc' 		=> '请填写收件人',
 			'match' 	=> 'is_numeric',
+			'search'	=> 'fulltext',
 			'update'	=> 'text',
-			//'list'		=> true,
+			'list'		=> true,
 		),
 
 		'from_uid'		=> array
@@ -70,8 +69,9 @@ return array
 			'default' 	=> '',
 			'desc' 		=> '请填写发件人',
 			'match' 	=> 'is_numeric',
+			'search'	=> 'fulltext',
 			'update'	=> 'text',
-			//'list'		=> true,
+			'list'		=> '{uid} > 0 ? {uid} : "系统"',
 		),
 
 		'name'		=> array
@@ -82,7 +82,8 @@ return array
 			'desc' 		=> '请填写发件标题',
 			'match' 	=> 'is_string',
 			'update'	=> 'text',
-			//'list'		=> true,
+			'search'	=> 'fulltext',
+			'list'		=> true,
 		),
 
 		'content'		=> array
@@ -93,7 +94,8 @@ return array
 			'desc' 		=> '请填写发件内容',
 			'match' 	=> 'is_string',
 			'update'	=> 'textarea',
-			//'list'		=> true,
+			'search'	=> 'fulltext',
+			'list'		=> true,
 		),
 
 		'type'		=> array
@@ -106,7 +108,7 @@ return array
 			'option' 	=> $type,
 			'update'	=> 'select',
 			//'search'	=> 'select',
-			//'list'		=> true,
+			'list'		=> true,
 		),
 
 		'status'		=> array
@@ -129,10 +131,6 @@ return array
 			'default' 	=> '1',
 			'desc' 		=> '请选择状态',
 			'match' 	=> 'is_numeric',
-			'option' 	=> $option,
-			'update'	=> 'radio',
-			'search'	=> 'select',
-			'list'		=> true,
 		),
 
 		'cdate'		=> array
@@ -167,7 +165,7 @@ return array
 				'state' => 1,
 			),
 			'type' => 'all',
-			'page' => array(12, 'list'),
+			'page' => array(15, 'list'),
 			'order' => array('id' => 'desc'),
 			'col' => '*',
 		),
@@ -186,4 +184,11 @@ return array
 			'col' => '*',
 		),
 	),
+
+	'manage' => array
+	(
+		'edit' => false,
+		'insert' => false,
+		'mul' => true,
+	),
 );

+ 7 - 7
database/outbox.php

@@ -15,7 +15,8 @@ $type = function()
 */
 $type = array
 (
-	1 => '系统消息',
+	//1 => '系统消息',
+	2 => '系统通知',
 );
 
 return array
@@ -48,8 +49,9 @@ return array
 			'default' 	=> '-1',
 			'desc' 		=> '请填写发件人',
 			'match' 	=> 'is_numeric',
+			'search'	=> 'fulltext',
 			//'update'	=> 'text',
-			//'list'		=> true,
+			'list'		=> '{uid} > 0 ? {uid} : "系统"',
 		),
 
 		'name'		=> array
@@ -59,6 +61,7 @@ return array
 			'default' 	=> '',
 			'desc' 		=> '请填写发件标题',
 			'match' 	=> 'is_string',
+			'search'	=> 'fulltext',
 			'update'	=> 'text',
 			'list'		=> true,
 		),
@@ -70,6 +73,7 @@ return array
 			'default' 	=> '',
 			'desc' 		=> '请填写发件内容',
 			'match' 	=> 'is_string',
+			'search'	=> 'fulltext',
 			'update'	=> 'textarea',
 			'list'		=> true,
 		),
@@ -84,7 +88,7 @@ return array
 			'option' 	=> $type,
 			'update'	=> 'select',
 			//'search'	=> 'select',
-			//'list'		=> true,
+			'list'		=> true,
 		),
 
 		'state'		=> array
@@ -94,10 +98,6 @@ return array
 			'default' 	=> '1',
 			'desc' 		=> '请选择状态',
 			'match' 	=> 'is_numeric',
-			'option' 	=> $option,
-			'update'	=> 'radio',
-			'search'	=> 'select',
-			'list'		=> true,
 		),
 
 		'cdate'		=> array

+ 17 - 18
database/type.php

@@ -1,16 +1,9 @@
 <?php
 
-# 定义几个常用的选项
-$option = array
-(
-	1 => '显示',
-	2 => '不显示',
-);
-
 $type = array
 (
-	1 => '不发送push',
-	2 => '发送push',
+	1 => '不发送',
+	2 => '发送',
 );
 
 return array
@@ -20,7 +13,6 @@ return array
 	# 显示给用户看的名称
 	'lang' => '消息类型',
 	'order' => 20,
-	'menu' => false,
 	# 数据结构
 	'struct' => array
 	(
@@ -44,20 +36,20 @@ return array
 			'desc' 		=> '请填写类型名称',
 			'match' 	=> 'is_string',
 			'update'	=> 'text',
-			//'list'		=> true,
+			'list'		=> true,
 		),
 
 		'type'		=> array
 		(
 			'type' 		=> 'tinyint-1',
-			'name' 		=> '是否同时发送push',
+			'name' 		=> '同时推送-暂未实现,实现后将可以同步发送微信、短信、客户端消息等',
 			'default' 	=> '1',
-			'desc' 		=> '请选择是否同时发送push',
+			'desc' 		=> '同时推送',
 			'match' 	=> 'is_numeric',
 			'option' 	=> $type,
 			'update'	=> 'radio',
 			//'search'	=> 'select',
-			//'list'		=> true,
+			'list'		=> true,
 		),
 
 		'state'		=> array
@@ -67,10 +59,6 @@ return array
 			'default' 	=> '1',
 			'desc' 		=> '请选择状态',
 			'match' 	=> 'is_numeric',
-			'option' 	=> $option,
-			'update'	=> 'radio',
-			'search'	=> 'select',
-			'list'		=> true,
 		),
 
 		'cdate'		=> array
@@ -89,6 +77,17 @@ return array
 	(
 		
 	),
+
+	'default' => array
+	(
+		'col' => 'name,type,state,cdate',
+		'value' => array
+		(
+			'1, "系统消息",1, 1,' . DEVER_TIME,
+			'2, "系统通知",1, 1,' . DEVER_TIME,
+			'11,"用户通知",1, 1,' . DEVER_TIME,
+		),
+	),
 	
 	# request 请求接口定义
 	'request' => array

+ 174 - 0
lib/Data.php

@@ -0,0 +1,174 @@
+<?php
+
+namespace Message\Lib;
+
+use Dever;
+use Passport\Src\User;
+use Passport\Src\Login;
+
+class Data
+{
+	public function __construct()
+	{
+        # 获取用户信息
+        $user = new User();
+        $this->user = $user->data();
+	}
+
+	/**
+     * 获取我的消息
+     * 
+     * @return mixed
+     */
+	public function read($uid, $type = false, $update = false, $status = false)
+	{
+        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';
+        $where .= ' and a.type <= 10';
+		# 读取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);
+            }
+		}
+        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)
+    {
+        return $this->read($uid, false, false, 1);
+    }
+
+	/**
+     * 查看我的消息
+     * 
+     * @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('错误的消息信息');
+	}
+
+	/**
+     * 推送消息
+     * 
+     * @return mixed
+     */
+	public function push($uid, $to_uid, $name, $content, $type = 1)
+	{
+        //$site 	    = intval(Dever::input('site', -1));
+
+        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
+                    }
+                }
+            }
+        }
+	}
+}