dever 6 years ago
parent
commit
3c55674a25
3 changed files with 90 additions and 10 deletions
  1. 20 10
      applet/src/Msg.php
  2. 60 0
      youzan/database/card.php
  3. 10 0
      youzan/src/Card.php

+ 20 - 10
applet/src/Msg.php

@@ -66,7 +66,7 @@ class Msg
 	}
 
 	# 发送单条模板消息
-	public function sendOne($key, $project_id, $touser, $page, $data, $form_id, $emphasis_keyword = '', $state = false)
+	public function sendOne($key, $project_id, $touser, $page, $data, $form_id = false, $emphasis_keyword = '', $state = false)
 	{
 		if ($project_id > 0 && $key && $touser && $page && $data) {
 			$info = Dever::db('applet/msg')->one(array('option_key' => $key, 'option_project_id' => $project_id));
@@ -109,16 +109,8 @@ class Msg
 				Dever::setInput('key', $info['key']);
 				Dever::setInput('project_id', $info['project_id']);
 				Dever::setInput('page', $info['page']);
-				$data = json_decode(base64_decode($info['content']), true);
-				if ($data) {
-					$send = array();
-					foreach ($data as $k => $v) {
-						$send[$v['key']]['value'] = $v['value'];
-					}
-					$send = json_encode($send, JSON_UNESCAPED_UNICODE);
-					Dever::setInput('data', $send);
-				}
 
+				$send = $this->getData($info['content']);
 				$this->sendMul();
 			}
 		}
@@ -126,6 +118,24 @@ class Msg
 		return;
 	}
 
+	# 解析data
+	public function getData($data = false)
+	{
+		$send = Dever::input('data');
+		if (!$send && $data) {
+			$data = json_decode(base64_decode($data), true);
+			if ($data) {
+				foreach ($data as $k => $v) {
+					$send[$v['key']]['value'] = $v['value'];
+				}
+				$send = json_encode($send, JSON_UNESCAPED_UNICODE);
+				Dever::setInput('data', $send);
+			}
+		}
+		
+		return $send;
+	}
+
 	# 发送多条模板消息 入队
 	public function sendMul()
 	{

+ 60 - 0
youzan/database/card.php

@@ -314,6 +314,66 @@ return array
 			//'list'		=> true,
 		),
 
+		'hr4'		=> array
+		(
+			'name' 		=> '微信模板消息设置',
+			'class'		=> '',//本项必须填写
+			'attr'		=> '',
+		),
+
+		'msg_key'		=> array
+		(
+			'type' 		=> 'varchar-20',
+			'name' 		=> '模板消息key',
+			'default' 	=> '',
+			'desc' 		=> '模板消息key',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			//'list'		=> true,
+			//'edit'		=> true,
+		),
+
+		'msg_page'		=> array
+		(
+			'type' 		=> 'varchar-200',
+			'name' 		=> '页面路径',
+			'default' 	=> 'pages/index/index',
+			'desc' 		=> '页面路径',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			//'list'		=> true,
+		),
+
+		'msg_content'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '模板内容',
+			'default' 	=> '',
+			'desc' 		=> '请输入内容',
+			'match' 	=> 'is_string',
+			'update'	=> array
+			(
+				array
+				(
+					'col'		=> 'key',
+					'name' 		=> '标识',
+					'default' 	=> '',
+					'desc' 		=> '请输入标识',
+					'match' 	=> 'is_string',
+					'update'	=> 'text',
+				),
+				array
+				(
+					'col' 		=> 'value',
+					'name' 		=> '内容值',
+					'default' 	=> '',
+					'desc' 		=> '内容值',
+					'match' 	=> 'is_string',
+					'update'	=> 'textarea',
+				),
+			),
+		),
+
 		'state'		=> array
 		(
 			'type' 		=> 'tinyint-1',

+ 10 - 0
youzan/src/Card.php

@@ -16,6 +16,7 @@ class Card
 	{
 		$key = Dever::input('key');
 		$user = Dever::input('user');
+		$page = Dever::input('page');
 		$project_id = Dever::input('project_id');
 		$info = Dever::db('youzan/card')->one(array('option_key' => $key, 'option_project_id' => $project_id));
 		if ($info) {
@@ -25,6 +26,15 @@ class Card
 				$key = array_rand($one);
 				if (isset($one[$key]) && $one[$key]) {
 					Dever::db('youzan/card_list')->update(array('where_id' => $one[$key]['id'], 'user' => $user, 'status' => 2));
+
+					# 检查info,有无msg_key,有则发送模板消息
+					if ($info['msg_key'] && $info['page'] && $info['msg_content']) {
+						if ($page) {
+							$info['msg_page'] = $page;
+						}
+						$send = Dever::load('applet/msg')->getData($info['msg_content']);
+						Dever::load('applet/msg')->sendOne($info['msg_key'], $project_id, $user, $info['msg_page'], $send);
+					}
 					return $one[$key];
 				}
 			}