dever 6 rokov pred
rodič
commit
36acc8a808

+ 6 - 0
applet/config/base.php

@@ -5,6 +5,12 @@ $config['base'] = array
 (
 	# 后台头部菜单
 	'top' => 'main/project_id-3',
+
+	# 定义队列
+	'queue' => array
+	(
+		'method' => 'db',
+	),
 );
 
 # 模板配置

+ 17 - 3
applet/database/msg.php

@@ -9,7 +9,8 @@ return array
 	'order' => 100,
 	'desc' => Dever::markdown('发送模板消息接口:'.Dever::url("applet/msg.send").'
 
-		id:消息id
+		key:消息key
+		project_id:项目id
 		touser:用户openid
 		page:页面路径
 		data:内容
@@ -26,16 +27,17 @@ return array
 			'desc' 		=> '',
 			'match' 	=> 'is_numeric',
 			'search'	=> 'order',
-			'list'		=> true,
+			//'list'		=> true,
 		),
 
 		'project_id'		=> array
 		(
 			'type' 		=> 'int-11',
-			'name' 		=> '项目',
+			'name' 		=> '项目ID',
 			'default' 	=> '',
 			'desc' 		=> '请输入项目',
 			'match' 	=> 'is_numeric',
+			'list'		=> true,
 		),
 		
 		'name'		=> array
@@ -49,6 +51,18 @@ return array
 			'list'		=> true,
 		),
 
+		'key'		=> array
+		(
+			'type' 		=> 'varchar-20',
+			'name' 		=> '模板消息key-通过key值搜索数据',
+			'default' 	=> '',
+			'desc' 		=> '模板消息key-通过key值搜索数据',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+			'edit'		=> true,
+		),
+
 		'template_id'		=> array
 		(
 			'type' 		=> 'varchar-120',

+ 16 - 1
applet/database/msg_form.php

@@ -1,5 +1,6 @@
 <?php
 
+$time = time()+(3600*24*7);
 return array
 (
 	# 表名
@@ -89,7 +90,7 @@ return array
 			'option' => array
 			(
 				'openid' => 'yes',
-				'cdate' => array(time()+(3600*24*7), '<='),
+				'cdate' => array($time, '<='),
 				'state' => 1,
 			),
 			'type' => 'all',
@@ -97,5 +98,19 @@ return array
 			'limit' => '0,100',
 			'col' => '*',
 		),
+
+		'getAllGroupByOpenid' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'cdate' => array($time, '<='),
+				'state' => 1,
+			),
+			'type' => 'all',
+			'group' => 'openid',
+			'order' => array('cdate' => 'desc'),
+			'col' => '*',
+		),
 	),
 );

+ 1 - 1
applet/src/Auth.php

@@ -49,6 +49,6 @@ class Auth
      */
 	public function token_api()
 	{
-		return $this->wechat->token();
+		return $this->wechat->token(false, false, 2000, true);
 	}
 }

+ 68 - 17
applet/src/Msg.php

@@ -29,31 +29,46 @@ class Msg
         );
 
         $data = json_encode($data);
-		Dever::setInput('touser', 'oIZ895adCNPtwyPX47Uv8ne8_xcM');
+		//Dever::setInput('touser', 'oIZ895bO9a_TT_ouYCQLPFMod57c');
 		
 		//Dever::setInput('touser', 'oIZ895bO9a_TT_ouYCQLPFMod57c');
 		Dever::setInput('page', $page);
 		Dever::setInput('data', $data);
-		Dever::setInput('form_id', '1526293953558');
-		Dever::setInput('id', 1);
+		//Dever::setInput('form_id', '1526295575657');
+		Dever::setInput('key', 'sendall');
+		Dever::setInput('project_id', '4');
 		$this->send();
 	}
 
-	# 发送模板消息
+	# 发送单条模板消息
 	public function send()
 	{
-		$id = Dever::input('id');
-		if ($id > 0) {
-			$info = Dever::db('applet/msg')->one($id);
+		$key = Dever::input('key');
+		$project_id = Dever::input('project_id');
+		$touser = Dever::input('touser');
+		$page = Dever::input('page');
+		$data = Dever::input('data');
+		$form_id = Dever::input('form_id');
+		$emphasis_keyword = Dever::input('emphasis_keyword');
+		$this->sendOne($key, $project_id, $touser, $page, $data, $form_id, $emphasis_keyword);
+
+		return 'ok';
+	}
+
+	# 发送单条模板消息
+	public function sendOne($key, $project_id, $touser, $page, $data, $form_id, $emphasis_keyword = '')
+	{
+		if ($project_id > 0 && $key && $touser && $page && $data) {
+			$info = Dever::db('applet/msg')->one(array('option_key' => $key, 'option_project_id' => $project_id));
 			if ($info) {
 				$update = array();
 				$update['project_id'] = $info['project_id'];
 				$update['msg_id'] = $info['id'];
-				$update['touser'] = Dever::input('touser');
-				$update['page'] = Dever::input('page');
-				$update['data'] = Dever::input('data');
-				$update['form_id'] = Dever::input('form_id');
-				$update['emphasis_keyword'] = Dever::input('emphasis_keyword');
+				$update['touser'] = $touser;
+				$update['page'] = $page;
+				$update['data'] = $data;
+				$update['form_id'] = $form_id;
+				$update['emphasis_keyword'] = $emphasis_keyword;
 
 				if (!$update['form_id']) {
 					$update['form_id'] = $this->getFormId($update['touser']);
@@ -71,10 +86,48 @@ class Msg
 				Core::run($info['project_id'], 'send_msg', 'msg.sendAction', 'msg.sendLog', 'applet', $id);
 			}
 		}
+	}
+
+	# 发送多条模板消息 入队
+	public function sendMul()
+	{
+		$key = Dever::input('key');
+		$project_id = Dever::input('project_id');
+		$page = Dever::input('page');
+		$data = Dever::input('data');
+		$emphasis_keyword = Dever::input('emphasis_keyword');
+		if ($id > 0 && $page && $data) {
+			# 获取所有拥有formid的openid,并去重
+			$data = Dever::db('applet/msg_form')->getAllGroupByOpenid();
+			print_r($data);die;
+			if ($data) {
+				Dever::import('queue');
+				foreach ($data as $k => $v) {
+					$param = array();
+					$param['key'] = $key;
+					$param['project_id'] = $project_id;
+					$param['touser'] = $v['openid'];
+					$param['page'] = $page;
+					$param['data'] = $data;
+					$param['form_id'] = $v['form_id'];
+					$param['emphasis_keyword'] = $emphasis_keyword;
+					Dever::push($param);
+				}
+			}
+		}
 
 		return 'ok';
 	}
 
+	# 发送多条模板消息 出队 每小时执行一次
+	public function cron()
+	{
+		Dever::import('queue');
+		while ($data = Dever::pop()) {
+			$this->sendOne($data['key'], $data['project_id'], $data['touser'], $data['page'], $data['data'], $data['form_id'], $data['emphasis_keyword']);
+		}
+	}
+
 	public function getFormId($openid)
 	{
 		# 获取一个form_id,取最新的100条,然后随机取
@@ -92,18 +145,16 @@ class Msg
 	# 记录form_id 之后加上清理过期的form_id 七天过期
 	public function write_form_id()
 	{
-		$id = Dever::input('id');
+		$id = Dever::input('project_id');
 		if ($id > 0) {
-			$info = Dever::db('applet/msg')->one($id);
-
 			$update = array();
-			$update['project_id'] = $info['project_id'];
+			$update['project_id'] = $id;
 			$update['form_id'] = Dever::input('form_id');
 			$update['openid'] = Dever::input('openid');
 
 			$where = array();
 			$where['option_openid'] = $update['openid'];
-			$where['option_project_id'] = $info['project_id'];
+			$where['option_project_id'] = $update['project_id'];
 			$where['option_form_id'] = $update['form_id'];
 
 			$id = Dever::upinto('applet/msg_form', $where, $update);

+ 1 - 1
component/src/Core.php

@@ -109,7 +109,7 @@ class Core
 			$update['where_id'] = $info['id'];
 			Dever::db($table)->update($update);
 
-			if ($table == 'component/unaudit') {
+			if ($table == 'component/unaudit' && $update['status'] == 2) {
 				$audit = array('option_user_id' => $info['user_id'], 'option_project_id' => $info['project_id'], 'option_version_id' => $info['version_id'], 'option_status' => 1);
 				$audit = Dever::db('component/auditing')->all($audit);
 				if ($audit) {

+ 3 - 0
config/base.php

@@ -5,6 +5,9 @@ $config['base'] = array
 (
 	# 后台头部菜单
 	'top' => 'main/project_id',
+
+	# 小程序内容端接口地址
+	'applet_content' => 'http://cm.5dev.cn/applet_on/content/v1/',
 );
 
 # 模板配置

+ 4 - 1
main/database/project.php

@@ -125,7 +125,10 @@ return array
 	
 	'manage' => array
 	(
-
+		'button' => array
+		(
+			//'同步小程序' => 'main/data.applet',
+		),
 	),
 
 	'top' => array

+ 20 - 50
main/src/Data.php

@@ -6,65 +6,35 @@ use Dever;
 
 class Data
 {
-    private function file()
+    private function applet()
     {
-        return Dever::data() . 'log.php';
-    }
-
-    private function config()
-    {
-        $config = include($this->file());
-        return $config;
-    }
-
-    # 从数据库生成维度和项目的配置文件
-    public function create()
-    {
-        $project = Dever::db('main/project')->all();
-        
-        $config = array();
-
-        if ($project) {
-            foreach ($project as $k => $v) {
-                $config['project'][$v['key']] = $v;
-            }
-        }
+        $host = Dever::config('base')->applet_content;
 
-        $col = Dever::db('main/col')->all();
+        if ($host) {
+            $host .= 'data.applet';
+            $uphost .= 'data.applet_wechat';
 
-        if ($col) {
-            foreach ($col as $k => $v) {
-                $config['col'][$v['key']] = $v;
-            }
-        }
+            $data = Dever::curl($host);
 
-        $data = '<?php return ' . var_export($config, true) . ';';
-        file_put_contents($this->file(), $data);
+            if ($data) {
+                foreach ($data as $k => $v) {
+                    $update = array();
+                    $update['appid'] = $v['appid'];
+                    $update['name'] = $v['name'];
+                    $update['secret'] = $v['secret'];
+                    $update['type'] = 3;
 
-        return true;
-    }
+                    $where = array();
+                    $where['option_appid'] = $v['appid'];
+                    $where['option_type'] = $update['type'];
 
-    public function add()
-    {
-        $project = Dever::input('project');
-        $config = $this->config();
-        if (!isset($config['project'][$project])) {
-            return true;
-        }
+                    $id = Dever::upinto('main/project', $where, $update);
 
-        $msg['project'] = $project;
-        $input = Dever::input();
-        if (isset($config['col'])) {
-            foreach ($config['col'] as $k => $v) {
-                if (isset($input[$k])) {
-                    $msg[$k] = $input[$k];
+                    if ($id > 0) {
+                        Dever::curl($uphost, array('id' => $v['id'], 'wechat_project_id' => $id));
+                    }
                 }
             }
         }
-        if ($msg) {
-            Dever::log($msg, 3);
-        }
-
-        return true;
     }
 }

+ 4 - 0
queue/index.php

@@ -0,0 +1,4 @@
+<?php
+define('DEVER_PACKAGE',  'queue');
+define('DEVER_APP_SETUP', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+include(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../boot.php');