[更新]简化代码,优化结构

This commit is contained in:
邹景立 2017-04-21 17:21:21 +08:00
parent cc342d727c
commit e1f6ae208e
10 changed files with 35 additions and 52 deletions

View File

@ -114,9 +114,8 @@ class Auth extends BasicAdmin {
public function forbid() { public function forbid() {
if (DataService::update($this->table)) { if (DataService::update($this->table)) {
$this->success("权限禁用成功!", ''); $this->success("权限禁用成功!", '');
} else {
$this->error("权限禁用失败,请稍候再试!");
} }
$this->error("权限禁用失败,请稍候再试!");
} }
/** /**
@ -125,9 +124,8 @@ class Auth extends BasicAdmin {
public function resume() { public function resume() {
if (DataService::update($this->table)) { if (DataService::update($this->table)) {
$this->success("权限启用成功!", ''); $this->success("权限启用成功!", '');
} else {
$this->error("权限启用失败,请稍候再试!");
} }
$this->error("权限启用失败,请稍候再试!");
} }
/** /**

View File

@ -56,12 +56,11 @@ class Config extends BasicAdmin {
* 文件存储配置 * 文件存储配置
*/ */
public function file() { public function file() {
$alert = [ $this->assign('alert', [
'type' => 'success', 'type' => 'success',
'title' => '操作提示', 'title' => '操作提示',
'content' => '文件引擎参数影响全局文件上传功能,请勿随意修改!' 'content' => '文件引擎参数影响全局文件上传功能,请勿随意修改!'
]; ]);
$this->assign('alert', $alert);
$this->title = '文件存储配置'; $this->title = '文件存储配置';
$this->index(); $this->index();
} }

View File

@ -126,9 +126,8 @@ class Index extends BasicAdmin {
} }
if (intval($this->request->request('id')) === intval(session('user.id'))) { if (intval($this->request->request('id')) === intval(session('user.id'))) {
return $this->_form('SystemUser', 'user/form'); return $this->_form('SystemUser', 'user/form');
} else {
$this->error('访问异常!');
} }
$this->error('访问异常!');
} }
} }

View File

@ -61,9 +61,8 @@ class Log extends BasicAdmin {
public function del() { public function del() {
if (DataService::update($this->table)) { if (DataService::update($this->table)) {
$this->success("日志删除成功!", ''); $this->success("日志删除成功!", '');
} else {
$this->error("日志删除失败,请稍候再试!");
} }
$this->error("日志删除失败,请稍候再试!");
} }
} }

View File

@ -116,9 +116,8 @@ class Menu extends BasicAdmin {
$this->error('别再删我菜单了...'); $this->error('别再删我菜单了...');
if (DataService::update($this->table)) { if (DataService::update($this->table)) {
$this->success("菜单删除成功!", ''); $this->success("菜单删除成功!", '');
} else {
$this->error("菜单删除失败,请稍候再试!");
} }
$this->error("菜单删除失败,请稍候再试!");
} }
/** /**
@ -128,9 +127,8 @@ class Menu extends BasicAdmin {
$this->error('请不要禁用菜单...'); $this->error('请不要禁用菜单...');
if (DataService::update($this->table)) { if (DataService::update($this->table)) {
$this->success("菜单禁用成功!", ''); $this->success("菜单禁用成功!", '');
} else {
$this->error("菜单禁用失败,请稍候再试!");
} }
$this->error("菜单禁用失败,请稍候再试!");
} }
/** /**
@ -139,9 +137,8 @@ class Menu extends BasicAdmin {
public function resume() { public function resume() {
if (DataService::update($this->table)) { if (DataService::update($this->table)) {
$this->success("菜单启用成功!", ''); $this->success("菜单启用成功!", '');
} else {
$this->error("菜单启用失败,请稍候再试!");
} }
$this->error("菜单启用失败,请稍候再试!");
} }
} }

View File

@ -93,9 +93,8 @@ class User extends BasicAdmin {
} }
if (DataService::save($this->table, ['id' => $data['id'], 'password' => md5($data['password'])], 'id')) { if (DataService::save($this->table, ['id' => $data['id'], 'password' => md5($data['password'])], 'id')) {
$this->success('密码修改成功,下次请使用新密码登录!', ''); $this->success('密码修改成功,下次请使用新密码登录!', '');
} else {
$this->error('密码修改失败,请稍候再试!');
} }
$this->error('密码修改失败,请稍候再试!');
} }
/** /**
@ -127,9 +126,8 @@ class User extends BasicAdmin {
} }
if (DataService::update($this->table)) { if (DataService::update($this->table)) {
$this->success("用户删除成功!", ''); $this->success("用户删除成功!", '');
} else {
$this->error("用户删除失败,请稍候再试!");
} }
$this->error("用户删除失败,请稍候再试!");
} }
/** /**
@ -141,9 +139,8 @@ class User extends BasicAdmin {
} }
if (DataService::update($this->table)) { if (DataService::update($this->table)) {
$this->success("用户禁用成功!", ''); $this->success("用户禁用成功!", '');
} else {
$this->error("用户禁用失败,请稍候再试!");
} }
$this->error("用户禁用失败,请稍候再试!");
} }
/** /**
@ -152,9 +149,8 @@ class User extends BasicAdmin {
public function resume() { public function resume() {
if (DataService::update($this->table)) { if (DataService::update($this->table)) {
$this->success("用户启用成功!", ''); $this->success("用户启用成功!", '');
} else {
$this->error("用户启用失败,请稍候再试!");
} }
$this->error("用户启用失败,请稍候再试!");
} }
} }

View File

@ -31,18 +31,18 @@ class Fans extends BasicAdmin {
* 定义当前默认数据表 * 定义当前默认数据表
* @var string * @var string
*/ */
protected $table='WechatFans'; protected $table = 'WechatFans';
/** /**
* 显示粉丝列表 * 显示粉丝列表
* @return array|string * @return array|string
*/ */
public function index() { public function index() {
$this->title='微信粉丝管理'; $this->title = '微信粉丝管理';
$db = Db::name($this->table); $db = Db::name($this->table);
$get = $this->request->get(); $get = $this->request->get();
if(isset($get['nickname']) && $get['nickname']!==''){ if (isset($get['nickname']) && $get['nickname'] !== '') {
$db->where('nickname','like',"%{$get['nickname']}%"); $db->where('nickname', 'like', "%{$get['nickname']}%");
} }
return parent::_list($db); return parent::_list($db);
} }
@ -50,13 +50,12 @@ class Fans extends BasicAdmin {
/** /**
* 同步粉丝列表 * 同步粉丝列表
*/ */
public function sync(){ public function sync() {
Db::name($this->table)->where('1=1')->delete(); Db::name($this->table)->where('1=1')->delete();
if(WechatService::syncAllFans('')){ if (WechatService::syncAllFans('')) {
$this->success('同步获取所有粉丝成功!',''); $this->success('同步获取所有粉丝成功!', '');
}else{
$this->error('同步获取粉丝失败,请稍候再试!');
} }
$this->error('同步获取粉丝失败,请稍候再试!');
} }
} }

View File

@ -79,9 +79,7 @@ class Keys extends BasicAdmin {
if ($this->request->isPost() && isset($data['keys'])) { if ($this->request->isPost() && isset($data['keys'])) {
$db = Db::name($this->table)->where('keys', $data['keys']); $db = Db::name($this->table)->where('keys', $data['keys']);
!empty($data['id']) && $db->where('id', 'neq', $data['id']); !empty($data['id']) && $db->where('id', 'neq', $data['id']);
if ($db->count() > 0) { $db->count() > 0 && $this->error('关键字已经存在,请使用其它关键字!');
$this->error('关键字已经存在,请使用其它关键字!');
}
} }
} }
@ -102,9 +100,8 @@ class Keys extends BasicAdmin {
public function forbid() { public function forbid() {
if (DataService::update($this->table)) { if (DataService::update($this->table)) {
$this->success("关键字禁用成功!", ''); $this->success("关键字禁用成功!", '');
} else {
$this->error("关键字禁用失败,请稍候再试!");
} }
$this->error("关键字禁用失败,请稍候再试!");
} }
/** /**
@ -113,9 +110,8 @@ class Keys extends BasicAdmin {
public function resume() { public function resume() {
if (DataService::update($this->table)) { if (DataService::update($this->table)) {
$this->success("关键字启用成功!", ''); $this->success("关键字启用成功!", '');
} else {
$this->error("关键字启用失败,请稍候再试!");
} }
$this->error("关键字启用失败,请稍候再试!");
} }
/** /**

View File

@ -99,9 +99,8 @@ class Menu extends BasicAdmin {
$wehcat = &load_wechat('Menu'); $wehcat = &load_wechat('Menu');
if (false !== $wehcat->deleteMenu()) { if (false !== $wehcat->deleteMenu()) {
$this->success('菜单取消成功,重新关注可立即生效!', ''); $this->success('菜单取消成功,重新关注可立即生效!', '');
} else {
$this->error('菜单取消失败,' . $wehcat->errMsg);
} }
$this->error('菜单取消失败,' . $wehcat->errMsg);
} }
/** /**

View File

@ -13,6 +13,8 @@
namespace app\wechat\controller; namespace app\wechat\controller;
use service\FileService;
use service\WechatService;
use think\Controller; use think\Controller;
use think\Db; use think\Db;
@ -32,7 +34,7 @@ class Review extends Controller {
$this->assign('type', $type); $this->assign('type', $type);
// 图文处理 // 图文处理
if ($type === 'news' && is_numeric($content) && !empty($content)) { if ($type === 'news' && is_numeric($content) && !empty($content)) {
$news = News::get($content, ['appid' => $this->real_appid]); $news = WechatService::getNewsById($content);
$this->assign('articles', $news['articles']); $this->assign('articles', $news['articles']);
} }
// 文章预览 // 文章预览
@ -48,15 +50,14 @@ class Review extends Controller {
/** /**
* 微信图片显示 * 微信图片显示
*/ */
public function wechatImage() { public function img() {
$url = input('get.url', ''); $url = $this->request->get('url', '');
$filename = 'upload/tmp/' . join('/', str_split(md5($url), 16)); $filename = 'wechat/tmp/' . join('/', str_split(md5($url), 16)) . '.jpg';
$realfile = ROOT_PATH . 'public/' . $filename; if (false === ($img = FileService::getFileUrl($filename))) {
file_exists(dirname($realfile)) || mkdir(dirname($realfile), 0755, true); $info = FileService::save($filename, file_get_contents($url));
if (!file_exists($realfile)) { $img = (is_array($info) && isset($info['url'])) ? $info['url'] : $url;
file_put_contents($realfile, file_get_contents($url));
} }
$this->redirect(pathinfo($this->requestbaseFile(true), PATHINFO_DIRNAME) . '/' . $filename); $this->redirect($img);
} }
} }