Browse Source

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

邹景立 8 years ago
parent
commit
e1f6ae208e

+ 2 - 4
application/admin/controller/Auth.php

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

+ 2 - 3
application/admin/controller/Config.php

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

+ 1 - 2
application/admin/controller/Index.php

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

+ 1 - 2
application/admin/controller/Log.php

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

+ 3 - 6
application/admin/controller/Menu.php

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

+ 4 - 8
application/admin/controller/User.php

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

+ 8 - 9
application/wechat/controller/Fans.php

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

+ 3 - 7
application/wechat/controller/Keys.php

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

+ 1 - 2
application/wechat/controller/Menu.php

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

+ 10 - 9
application/wechat/controller/Review.php

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