作者 Karson

修复使用微信管理模块的BUG

修复configvalue辅助函数BUG
更新后台清除缓存的JS脚本
@@ -213,7 +213,7 @@ CREATE TABLE `fa_configvalue` ( @@ -213,7 +213,7 @@ CREATE TABLE `fa_configvalue` (
213 -- Records of `fa_configvalue` 213 -- Records of `fa_configvalue`
214 -- ---------------------------- 214 -- ----------------------------
215 BEGIN; 215 BEGIN;
216 -INSERT INTO `fa_configvalue` VALUES ('wechat', '微信菜单', '{\"menu\":[{\"name\":\"极速后台\",\"sub_button\":[{\"name\":\"官网\",\"type\":\"view\",\"url\":\"http:\\/\\/www.fastadmin.net\"},{\"name\":\"演示站\",\"type\":\"view\",\"url\":\"http:\\/\\/demo.fastadmin.net\"}]},{\"name\":\"联系客\",\"type\":\"click\",\"key\":\"58cb852984970\"},{\"name\":\"关于我们\",\"type\":\"click\",\"key\":\"58bf944aa0777\"}],\"config\":[{\"id\":\"default.subscribe.message\",\"name\":\"关注后自动推送内容\",\"value\":\"欢迎关注我们!\"},{\"id\":\"cccdddd\",\"name\":\"dfsdffdsfdsdfsdfs\",\"value\":\"fsfsfsdfsdfdsfdsgggg\"}]}', '0', '1492186828', '5', 'normal'); 216 +INSERT INTO `fa_configvalue` VALUES ('wechat', '微信菜单', '{\"menu\":[{\"name\":\"极速后台\",\"sub_button\":[{\"name\":\"官网\",\"type\":\"view\",\"url\":\"http:\\/\\/www.fastadmin.net\"},{\"name\":\"演示站\",\"type\":\"view\",\"url\":\"http:\\/\\/demo.fastadmin.net\"}]},{\"name\":\"联系客\",\"type\":\"click\",\"key\":\"58cb852984970\"},{\"name\":\"关于我们\",\"type\":\"click\",\"key\":\"58bf944aa0777\"}],\"config\":[{\"id\":\"default.subscribe.message\",\"name\":\"关注后自动推送内容\",\"value\":\"欢迎关注我们!\"},{\"id\":\"cccdddd\",\"name\":\"dfsdffdsfdsdfsdfs\",\"value\":\"fsfsfsdfsdfdsfdsgggg\"}]}', '0', '1493986907', '5', 'normal');
217 COMMIT; 217 COMMIT;
218 218
219 -- ---------------------------- 219 -- ----------------------------
@@ -373,7 +373,14 @@ CREATE TABLE `fa_wechat_autoreply` ( @@ -373,7 +373,14 @@ CREATE TABLE `fa_wechat_autoreply` (
373 `updatetime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', 373 `updatetime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
374 `status` varchar(30) NOT NULL DEFAULT '' COMMENT '状态', 374 `status` varchar(30) NOT NULL DEFAULT '' COMMENT '状态',
375 PRIMARY KEY (`id`) 375 PRIMARY KEY (`id`)
376 -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='微信自动回复表'; 376 +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='微信自动回复表';
  377 +
  378 +-- ----------------------------
  379 +-- Records of `fa_wechat_autoreply`
  380 +-- ----------------------------
  381 +BEGIN;
  382 +INSERT INTO `fa_wechat_autoreply` VALUES ('1', '输入hello', 'hello', '58c7d908c4570', '123', '1493366855', '1493366855', 'normal'), ('2', '输入你好', '你好', '58fdfaa9e1965', 'sad', '1493704976', '1493704976', 'normal');
  383 +COMMIT;
377 384
378 -- ---------------------------- 385 -- ----------------------------
379 -- Table structure for `fa_wechat_context` 386 -- Table structure for `fa_wechat_context`
@@ -415,7 +422,7 @@ CREATE TABLE `fa_wechat_response` ( @@ -415,7 +422,7 @@ CREATE TABLE `fa_wechat_response` (
415 -- Records of `fa_wechat_response` 422 -- Records of `fa_wechat_response`
416 -- ---------------------------- 423 -- ----------------------------
417 BEGIN; 424 BEGIN;
418 -INSERT INTO `fa_wechat_response` VALUES ('1', '签到送积分', '58adaf7876aab', 'app', '{\"app\":\"signin\"}', '', '1487777656', '0', 'normal'), ('2', '关于我们', '58bf944aa0777', 'app', '{\"app\":\"article\",\"id\":\"1\"}', '', '1488950346', '0', 'normal'), ('3', '测试我们', '58c7d908c4570', 'text', '{\"content\":\"\\u8fd4\\u56de\\u6210\\u529f\\u5566\\uff01\"}', '测试我们', '1489492232', '0', 'normal'), ('4', '联系客服', '58cb852984970', 'app', '{\"app\":\"service\"}', '', '1489732905', '0', 'normal'); 425 +INSERT INTO `fa_wechat_response` VALUES ('1', '签到送积分', '58adaf7876aab', 'app', '{\"app\":\"signin\"}', '', '1487777656', '1487777656', 'normal'), ('2', '关于我们', '58bf944aa0777', 'app', '{\"app\":\"page\",\"id\":\"1\"}', '', '1488950346', '1488950346', 'normal'), ('3', '自动回复1', '58c7d908c4570', 'text', '{\"content\":\"world\"}', '', '1489492232', '1489492232', 'normal'), ('4', '联系客服', '58cb852984970', 'app', '{\"app\":\"service\"}', '', '1489732905', '1489732905', 'normal'), ('5', '自动回复2', '58fdfaa9e1965', 'text', '{\"content\":\"我是FastAdmin!\"}', '', '1493039785', '1493039785', 'normal');
419 COMMIT; 426 COMMIT;
420 427
421 SET FOREIGN_KEY_CHECKS = 1; 428 SET FOREIGN_KEY_CHECKS = 1;
@@ -64,7 +64,7 @@ class Menu extends Backend @@ -64,7 +64,7 @@ class Menu extends Backend
64 public function sync($ids = NULL) 64 public function sync($ids = NULL)
65 { 65 {
66 $this->code = -1; 66 $this->code = -1;
67 - $app = new Application(Config::get('wechat')->toArray()); 67 + $app = new Application(Config::get('wechat'));
68 68
69 try 69 try
70 { 70 {
@@ -74,7 +74,7 @@ if (!function_exists('configvalue')) @@ -74,7 +74,7 @@ if (!function_exists('configvalue'))
74 */ 74 */
75 function configvalue($id) 75 function configvalue($id)
76 { 76 {
77 - $data = Configvalue::get('wechat'); 77 + $data = Configvalue::get($id);
78 return $data ? $data->content : null; 78 return $data ? $data->content : null;
79 } 79 }
80 80
@@ -3,11 +3,12 @@ @@ -3,11 +3,12 @@
3 namespace app\index\controller; 3 namespace app\index\controller;
4 4
5 use app\common\controller\Frontend; 5 use app\common\controller\Frontend;
  6 +use app\common\model\WechatAutoreply;
6 use app\common\model\WechatContext; 7 use app\common\model\WechatContext;
7 use app\common\model\WechatResponse; 8 use app\common\model\WechatResponse;
  9 +use EasyWeChat\Foundation\Application;
8 use EasyWeChat\Payment\Order; 10 use EasyWeChat\Payment\Order;
9 use fast\service\Wechat as WechatService; 11 use fast\service\Wechat as WechatService;
10 -use fast\third\Application;  
11 use think\Config; 12 use think\Config;
12 use think\Log; 13 use think\Log;
13 14
@@ -22,7 +23,7 @@ class Wechat extends Frontend @@ -22,7 +23,7 @@ class Wechat extends Frontend
22 public function _initialize() 23 public function _initialize()
23 { 24 {
24 parent::_initialize(); 25 parent::_initialize();
25 - $this->app = new Application(Config::getSecret('wechat')->toArray()); 26 + $this->app = new Application(Config::get('wechat'));
26 } 27 }
27 28
28 /** 29 /**
@@ -68,11 +69,11 @@ class Wechat extends Frontend @@ -68,11 +69,11 @@ class Wechat extends Frontend
68 break; 69 break;
69 } 70 }
70 71
71 - $response = $WechatResponse->where(["eventkey" => $eventkey, 'status' => FA_STATUS_NORMAL])->get(); 72 + $response = $WechatResponse->where(["eventkey" => $eventkey, 'status' => 'normal'])->find();
72 if ($response) 73 if ($response)
73 { 74 {
74 $content = (array) json_decode($response['content'], TRUE); 75 $content = (array) json_decode($response['content'], TRUE);
75 - $context = $WechatContext->where(['openid' => $openid])->get(); 76 + $context = $WechatContext->where(['openid' => $openid])->find();
76 $data = ['eventkey' => $eventkey, 'command' => '', 'refreshtime' => time(), 'openid' => $openid]; 77 $data = ['eventkey' => $eventkey, 'command' => '', 'refreshtime' => time(), 'openid' => $openid];
77 if ($context) 78 if ($context)
78 { 79 {
@@ -81,7 +82,7 @@ class Wechat extends Frontend @@ -81,7 +82,7 @@ class Wechat extends Frontend
81 } 82 }
82 else 83 else
83 { 84 {
84 - $id = $WechatContext->data($data)->insert(); 85 + $id = $WechatContext->data($data)->save();
85 $data['id'] = $id; 86 $data['id'] = $id;
86 } 87 }
87 $result = $WechatService->response($this, $openid, $content, $data); 88 $result = $WechatService->response($this, $openid, $content, $data);
@@ -99,10 +100,10 @@ class Wechat extends Frontend @@ -99,10 +100,10 @@ class Wechat extends Frontend
99 case 'link': //链接消息 100 case 'link': //链接消息
100 default: //其它消息 101 default: //其它消息
101 //上下文事件处理 102 //上下文事件处理
102 - $context = $WechatContext->where([['openid', $openid], ['refreshtime', '>=', time() - 1800]])->get(); 103 + $context = $WechatContext->where(['openid' => ['=', $openid], 'refreshtime' => ['>=', time() - 1800]])->find();
103 if ($context && $context['eventkey']) 104 if ($context && $context['eventkey'])
104 { 105 {
105 - $response = $WechatResponse->where(['eventkey' => $context['eventkey'], 'status' => FA_STATUS_NORMAL])->get(); 106 + $response = $WechatResponse->where(['eventkey' => $context['eventkey'], 'status' => 'normal'])->find();
106 if ($response) 107 if ($response)
107 { 108 {
108 $WechatContext->data(array('refreshtime' => time()))->where('id', $context['id'])->update(); 109 $WechatContext->data(array('refreshtime' => time()))->where('id', $context['id'])->update();
@@ -117,15 +118,15 @@ class Wechat extends Frontend @@ -117,15 +118,15 @@ class Wechat extends Frontend
117 //自动回复处理 118 //自动回复处理
118 if ($message->MsgType == 'text') 119 if ($message->MsgType == 'text')
119 { 120 {
120 - $wechat_autoreply = new Orm('wechat_autoreply');  
121 - $autoreply = $wechat_autoreply->where(['text' => $message->Content, 'status' => FA_STATUS_NORMAL])->get(); 121 + $wechat_autoreply = new WechatAutoreply();
  122 + $autoreply = $wechat_autoreply->where(['text' => $message->Content, 'status' => 'normal'])->find();
122 if ($autoreply) 123 if ($autoreply)
123 { 124 {
124 - $response = $WechatResponse->where(["eventkey" => $autoreply['eventkey'], 'status' => FA_STATUS_NORMAL])->get(); 125 + $response = $WechatResponse->where(["eventkey" => $autoreply['eventkey'], 'status' => 'normal'])->find();
125 if ($response) 126 if ($response)
126 { 127 {
127 $content = (array) json_decode($response['content'], TRUE); 128 $content = (array) json_decode($response['content'], TRUE);
128 - $context = $WechatContext->where(['openid' => $openid])->get(); 129 + $context = $WechatContext->where(['openid' => $openid])->find();
129 $result = $WechatService->response($this, $openid, $content, $context); 130 $result = $WechatService->response($this, $openid, $content, $context);
130 if ($result) 131 if ($result)
131 { 132 {
@@ -9,6 +9,7 @@ use app\common\model\UserThird; @@ -9,6 +9,7 @@ use app\common\model\UserThird;
9 use EasyWeChat\Message\News; 9 use EasyWeChat\Message\News;
10 use EasyWeChat\Message\Transfer; 10 use EasyWeChat\Message\Transfer;
11 use fast\Date; 11 use fast\Date;
  12 +use think\Config;
12 13
13 /** 14 /**
14 * Wechat服务类 15 * Wechat服务类
@@ -62,7 +63,6 @@ class Wechat @@ -62,7 +63,6 @@ class Wechat
62 // 微信输入交互内容指令 63 // 微信输入交互内容指令
63 public function command($obj, $openid, $content, $context) 64 public function command($obj, $openid, $content, $context)
64 { 65 {
65 - $content = [];  
66 $response = FALSE; 66 $response = FALSE;
67 if (isset($content['app'])) 67 if (isset($content['app']))
68 { 68 {
@@ -131,7 +131,7 @@ class Wechat @@ -131,7 +131,7 @@ class Wechat
131 // 微信点击菜单event指令 131 // 微信点击菜单event指令
132 public function response($obj, $openid, $content, $context) 132 public function response($obj, $openid, $content, $context)
133 { 133 {
134 - $content = []; 134 + $upload = Config::get('upload');
135 $response = FALSE; 135 $response = FALSE;
136 if (isset($content['app'])) 136 if (isset($content['app']))
137 { 137 {
@@ -176,8 +176,8 @@ class Wechat @@ -176,8 +176,8 @@ class Wechat
176 { 176 {
177 $news = new News(); 177 $news = new News();
178 $news->title = $pageinfo['title']; 178 $news->title = $pageinfo['title'];
179 - $news->url = $pageinfo['outlink'] ? $pageinfo['outlink'] : url('page/show/' . $pageinfo['id'], 1);  
180 - $news->image = cdn($pageinfo['image']); 179 + $news->url = $pageinfo['url'] ? $pageinfo['url'] : url('index/page/show', ['id' => $pageinfo['id']], true, true);
  180 + $news->image = $upload['cdnurl'] . $pageinfo['image'];
181 $news->description = $pageinfo['description']; 181 $news->description = $pageinfo['description'];
182 $response[] = $news; 182 $response[] = $news;
183 } 183 }
@@ -190,8 +190,8 @@ class Wechat @@ -190,8 +190,8 @@ class Wechat
190 { 190 {
191 $news = new News(); 191 $news = new News();
192 $news->title = $pageinfo['title']; 192 $news->title = $pageinfo['title'];
193 - $news->url = $pageinfo['outlink'] ? $pageinfo['outlink'] : url('page/show/' . $pageinfo['id'], 1);  
194 - $news->image = cdn($pageinfo['image']); 193 + $news->url = $pageinfo['url'] ? $pageinfo['url'] : url('index/page/show', ['id' => $pageinfo['id']], true, true);
  194 + $news->image = $upload['cdnurl'] . $pageinfo['image'];
195 $news->description = $pageinfo['description']; 195 $news->description = $pageinfo['description'];
196 return $news; 196 return $news;
197 } 197 }
@@ -48,17 +48,24 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'adminlte', 'validator'], f @@ -48,17 +48,24 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'adminlte', 'validator'], f
48 }); 48 });
49 49
50 //清除缓存 50 //清除缓存
51 - $(document).on('click', "[data-toggle='wipeCache']", function () { 51 + $(document).on('click', "[data-toggle='wipecache']", function () {
52 $.ajax({ 52 $.ajax({
53 - url: 'ajax/wipeCache', 53 + url: 'ajax/wipecache',
54 dataType: 'json', 54 dataType: 'json',
55 cache: false, 55 cache: false,
56 success: function (ret) { 56 success: function (ret) {
57 - if (ret.code === 1) {  
58 - Backend.api.toastr.success(ret.msg); 57 + if (ret.hasOwnProperty("code")) {
  58 + var msg = ret.hasOwnProperty("msg") && ret.msg != "" ? ret.msg : "";
  59 + if (ret.code === 1) {
  60 + Toastr.success(msg ? msg : __('Wipe cache completed'));
  61 + } else {
  62 + Toastr.error(msg ? msg : __('Wipe cache failed'));
  63 + }
59 } else { 64 } else {
60 - Backend.api.toastr.error('清除系统缓存失败!'); 65 + Toastr.error(__('Unknown data format'));
61 } 66 }
  67 + }, error: function () {
  68 + Toastr.error(__('Network error'));
62 } 69 }
63 }); 70 });
64 }); 71 });