From ded54b79caaa2337bf0feb3bb0974dd9ea6b148b Mon Sep 17 00:00:00 2001 From: molong Date: Tue, 15 Aug 2017 22:09:59 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E5=A4=8Dbug=202=E3=80=81?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=A0=8F=E7=9B=AE=E5=88=86=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=88=92=E5=88=86=203=E3=80=81=E5=89=8D=E5=8F=B0=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=BE=AE=E4=BF=A1=E5=BC=80=E5=8F=91=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Category.php | 17 +++- application/admin/view/category/edit.html | 11 +++ application/admin/view/category/index.html | 108 ++++++++++++--------- application/common/controller/Addons.php | 16 ++- application/common/controller/Admin.php | 2 +- application/common/controller/Base.php | 3 +- application/common/controller/Fornt.php | 70 +++++++++++++ application/common/controller/User.php | 13 ++- application/common/model/Attribute.php | 4 +- application/common/model/Category.php | 2 +- application/common/model/Content.php | 4 + application/common/model/FormAttr.php | 2 +- application/common/model/User.php | 67 ++++++++++--- application/common/validate/Attribute.php | 2 +- 14 files changed, 240 insertions(+), 81 deletions(-) diff --git a/application/admin/controller/Category.php b/application/admin/controller/Category.php index 99766634..e3b2f895 100644 --- a/application/admin/controller/Category.php +++ b/application/admin/controller/Category.php @@ -17,16 +17,23 @@ class Category extends Admin { $this->getContentMenu(); } - public function index() { + public function index($model_id = '') { $map = array('status' => array('gt', -1)); + if ($model_id) { + $map['model_id'] = $model_id; + } $list = db('Category')->where($map)->order('sort asc,id asc')->column('*', 'id'); if (!empty($list)) { $tree = new \com\Tree(); $list = $tree->toFormatTree($list); } + $subsql = db('Attribute')->where('name', 'category_id')->fetchSql(true)->column('model_id'); + $model_list = model('Model')->where('id IN ('. $subsql.')')->select(); $this->assign('tree', $list); + $this->assign('model_list', $model_list); + $this->assign('model_id', $model_id); $this->setMeta('栏目列表'); return $this->fetch(); } @@ -61,10 +68,14 @@ class Category extends Admin { return $this->error('指定的上级分类不存在或被禁用!'); } } + $subsql = db('Attribute')->where('name', 'category_id')->fetchSql(true)->column('model_id'); + $model_list = model('Model')->where('id IN ('. $subsql.')')->select(); + /* 获取分类信息 */ $info = $id ? db('Category')->find($id) : ''; $this->assign('info', $info); + $this->assign('model_list', $model_list); $this->assign('category', $cate); $this->setMeta('编辑分类'); return $this->fetch(); @@ -93,8 +104,12 @@ class Category extends Admin { return $this->error('指定的上级分类不存在或被禁用!'); } } + $subsql = db('Attribute')->where('name', 'category_id')->fetchSql(true)->column('model_id'); + $model_list = model('Model')->where('id IN ('. $subsql.')')->select(); + /* 获取分类信息 */ $this->assign('info', null); + $this->assign('model_list', $model_list); $this->assign('category', $cate); $this->setMeta('新增分类'); return $this->fetch('edit'); diff --git a/application/admin/view/category/edit.html b/application/admin/view/category/edit.html index 8e2ff8c0..e3c88d75 100644 --- a/application/admin/view/category/edit.html +++ b/application/admin/view/category/edit.html @@ -45,6 +45,17 @@ +
+ +
+ +
+
diff --git a/application/admin/view/category/index.html b/application/admin/view/category/index.html index 0711efa4..783a3d36 100644 --- a/application/admin/view/category/index.html +++ b/application/admin/view/category/index.html @@ -15,54 +15,68 @@
- - - - - - - - - - - - - - {volist name="tree" id="list"} - - - - - - - - - +
+
-
ID名称排序发布状态操作
{$list['id']} - {$list['level_show']} - {$list['title']} - - - - {$list['sort']}{$list['allow_publish']?'是':'否'} - {if $list['status']} - 启用 - {else/} - 禁用 - {/if} - - 编辑 - {if $list['status']} - 禁用 - {else/} - 启用 - {/if} - 删除 - 移动 - 合并 -
+ +
+
+ + + + + + + + + + + + + + {volist name="tree" id="list"} + + + + + + + + + + {/volist} + +
ID名称排序发布状态操作
{$list['id']} + {$list['level_show']} + {$list['title']} + + + + {$list['sort']}{$list['allow_publish']?'是':'否'} + {if $list['status']} + 启用 + {else/} + 禁用 + {/if} + + 编辑 + {if $list['status']} + 禁用 + {else/} + 启用 + {/if} + 删除 + 移动 + 合并 +
+
+
+
diff --git a/application/common/controller/Addons.php b/application/common/controller/Addons.php index 1b9e4676..9e279e90 100644 --- a/application/common/controller/Addons.php +++ b/application/common/controller/Addons.php @@ -30,25 +30,23 @@ class Addons extends Base { if (is_file($this->addon_path . 'config.php')) { $this->config_file = $this->addon_path . 'config.php'; } + + $this->template(); } - public function template($template) { + public function template() { $mc = $this->getAddonsName(); $ac = input('ac', '', 'trim,strtolower'); $parse_str = \think\Config::get('parse_str'); $parse_str['__ADDONROOT__'] = ROOT_PATH . "/addons/{$mc}"; \think\Config::set('parse_str', $parse_str); - if ($template) { - $template = $template; - } else { - $template = $mc . "/" . $ac; - } - $this->view->engine( - array('view_path' => "addons/" . $mc . "/view/") + array( + 'view_path' => "addons/" . $mc . "/view/", + 'replace' => array('__ADDONROOT__'=>ROOT_PATH . "/addons/{$mc}") + ) ); - echo $this->fetch($template); } final public function getAddonsName() { diff --git a/application/common/controller/Admin.php b/application/common/controller/Admin.php index 9b758650..bf68a3b3 100644 --- a/application/common/controller/Admin.php +++ b/application/common/controller/Admin.php @@ -208,7 +208,7 @@ class Admin extends Base { $menu = array(); foreach ($list as $key => $value) { $class = "\\addons\\" . strtolower($value['name']) . "\\controller\\Admin"; - if (is_file(ROOT_PATH . $class . ".php")) { + if (is_file(ROOT_PATH .'/addons/' . strtolower($value['name']) . "/controller/Admin.php")) { $action = get_class_methods($class); $value['url'] = "admin/addons/execute?mc=" . strtolower($value['name']) . "&ac=" . $action[0]; $menu[$key] = $value; diff --git a/application/common/controller/Base.php b/application/common/controller/Base.php index 72d3725b..0bec478b 100644 --- a/application/common/controller/Base.php +++ b/application/common/controller/Base.php @@ -43,7 +43,8 @@ class Base extends \think\Controller { $ops = ucwords($op); $class = "\\addons\\{$mc}\\controller\\{$ops}"; $addons = new $class; - $addons->$ac(); + + return $addons->$ac(); } else { $this->error('没有指定插件名称,控制器或操作!'); } diff --git a/application/common/controller/Fornt.php b/application/common/controller/Fornt.php index e378b48c..5efe78f1 100644 --- a/application/common/controller/Fornt.php +++ b/application/common/controller/Fornt.php @@ -11,6 +11,7 @@ namespace app\common\controller; class Fornt extends Base { + public $wechat_oauth; public function _initialize() { parent::_initialize(); @@ -27,6 +28,75 @@ class Fornt extends Base { //主题设置 $this->setThemes(); + + //微信访问时 + if ($this->isMobile() && $this->is_wechat()) { + if (!session('oauth')) { + $this->getOpentId(); + }else{ + $this->wechat_oauth = session('oauth'); + $this->assign('oauth', session('oauth')); + } + + //微信用户直接使用微信登录 + $this->WechatUser(); + } + } + + /** + * 微信用户登录 + */ + protected function WechatUser(){ + if (!is_login()) { + $openid = $this->wechat_oauth['openid']; + //若系统内存在则直接登录,不存在不登录 + $result = model('User')->login($openid, '', 5); + if ($result == -1) { + $user = & load_wechat('User'); + $wechat_user = $user->getUserInfo($this->wechat_oauth['openid']); + + $result = model('User')->register($openid, $openid, $openid, $openid.'@openid.com', true, array('openid'=>$openid,'nickname'=>$this->jsonName($wechat_user['nickname']),'headimgurl'=>$wechat_user['headimgurl'])); + } + return $result; + }else{ + return true; + } + } + + /** + +---------------------------------------------------------- + * 过滤用户昵称里面的特殊字符 + +---------------------------------------------------------- + * @param string $str 待输出的用户昵称 + +---------------------------------------------------------- + */ + protected function jsonName($str) { + if($str){ + $return = ''; + $length = mb_strlen($str,'utf-8'); + for ($i=0; $i < $length; $i++) { + $_tmpStr = mb_substr($str,$i,1,'utf-8'); + if(strlen($_tmpStr) >= 4){ + $return .= ''; + }else{ + $return .= $_tmpStr; + } + } + }else{ + $return = 'wechat_'.time(); + } + return $return; + } + + protected function getOpentId(){ + $oauth = &load_wechat('Oauth'); + $user_oauth = $oauth->getOauthAccessToken(); + if ($user_oauth) { + session('oauth',$user_oauth); + }else{ + $uri = $oauth->getOauthRedirect('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); + header("Location:".$uri); + } } //当前栏目导航 diff --git a/application/common/controller/User.php b/application/common/controller/User.php index 43dcbd04..730dcd22 100644 --- a/application/common/controller/User.php +++ b/application/common/controller/User.php @@ -15,7 +15,7 @@ class User extends Fornt { parent::_initialize(); if (!is_login() and !in_array($this->url, array('user/login/index', 'user/index/verify'))) { - $this->redirect('user/login/index');exit(); + return $this->redirect('user/login/index'); } elseif (is_login()) { $user = model('User')->getInfo(session('user_auth.uid')); // if (!$this->checkProfile($user) && $this->url !== 'user/profile/index') { @@ -24,8 +24,17 @@ class User extends Fornt { $this->assign('user', $user); //设置会员中心菜单 - $this->setMenu(); + //$this->setMenu(); } + + if ($this->is_wechat() && !session('wechat_user')) { + $user = & load_wechat('User'); + $wechat_user = $user->getUserInfo($this->wechat_oauth['openid']); + //更新用户信息 + session('wechat_user', $wechat_user); + } + + $this->assign('wechat_user', session('wechat_user')); } protected function setMenu() { diff --git a/application/common/model/Attribute.php b/application/common/model/Attribute.php index c7d53100..0b700edb 100644 --- a/application/common/model/Attribute.php +++ b/application/common/model/Attribute.php @@ -59,12 +59,12 @@ class Attribute extends Base{ public function getFieldlist($map,$index='id'){ $list = array(); - $row = db('Attribute')->field('*,remark as help,type,extra as "option"')->where($map)->order('group_id asc, sort asc')->select(); + $row = db('Attribute')->field('*,remark as help,type,extra as "option",model_id')->where($map)->order('group_id asc, sort asc')->select(); foreach ($row as $key => $value) { if (in_array($value['type'],array('checkbox','radio','select','bool'))) { $value['option'] = parse_field_attr($value['extra']); } elseif ($value['type'] == 'bind') { - $extra = parse_field_bind($value['extra']); + $extra = parse_field_bind($value['extra'], '', $value['model_id']); $option = array(); foreach ($extra as $k => $v) { $option[$v['id']] = $v['title_show']; diff --git a/application/common/model/Category.php b/application/common/model/Category.php index c76a7d8c..3239910b 100644 --- a/application/common/model/Category.php +++ b/application/common/model/Category.php @@ -15,7 +15,7 @@ namespace app\common\model; class Category extends Base{ protected $name = "Category"; - protected $auto = array('update_time', 'icon'=>1, 'status'=>1); + protected $auto = array('update_time', 'status'=>1); protected $type = array( 'icon' => 'integer', diff --git a/application/common/model/Content.php b/application/common/model/Content.php index a3dbb32e..9cc8d205 100644 --- a/application/common/model/Content.php +++ b/application/common/model/Content.php @@ -14,4 +14,8 @@ namespace app\common\model; */ class Content extends BaseModel{ + protected $type = array( + 'create_time' => 'integer', + 'update_time' => 'integer', + ); } \ No newline at end of file diff --git a/application/common/model/FormAttr.php b/application/common/model/FormAttr.php index f7f96dc9..18b5c90c 100644 --- a/application/common/model/FormAttr.php +++ b/application/common/model/FormAttr.php @@ -17,7 +17,7 @@ class FormAttr extends Base{ protected $type = array( 'id' => 'integer', ); - + protected static function init(){ self::afterInsert(function($data){ if ($data['form_id']) { diff --git a/application/common/model/User.php b/application/common/model/User.php index 0321f44e..a76df4a7 100644 --- a/application/common/model/User.php +++ b/application/common/model/User.php @@ -79,13 +79,17 @@ class User extends Base{ } /** - * 用户登录模型 - */ - public function login($username = '', $password = '', $type = 1){ + * 用户登录模型 + * @param string $username [description] + * @param string $password [description] + * @param integer $type 登录类型,1为用户名登录2为邮箱登录3为手机登录4为用户ID登录5为微信登录 + * @return [type] [description] + */ + public function login($username = '', $password = '', $type = 1) { $map = array(); - if (\think\Validate::is($username,'email')) { + if (\think\Validate::is($username, 'email')) { $type = 2; - }elseif (preg_match("/^1[34578]{1}\d{9}$/",$username)) { + } elseif (preg_match("/^1[34578]{1}\d{9}$/", $username)) { $type = 3; } switch ($type) { @@ -102,23 +106,53 @@ class User extends Base{ $map['uid'] = $username; break; case 5: - $map['uid'] = $username; + $map['openid'] = $username; break; default: - return 0; //参数错误 + return 0; //参数错误 + } + if (!$username) { + return false; } $user = $this->where($map)->find(); - if(isset($user['status']) && $user['status']){ - /* 验证用户密码 */ - if(md5($password.$user['salt']) === $user['password']){ + if (isset($user['uid']) && $user['uid'] && $user['status']) { + if ($type == 3) { + //手机验证手机动态密码 + if ($password == session('mobile_login_code')) { + $this->autoLogin($user); //更新用户登录信息 + return $user['uid']; + }else{ + return -5; + } + } elseif ($type == 5) { $this->autoLogin($user); //更新用户登录信息 - return $user['uid']; //登录成功,返回用户ID + return $user['uid']; } else { - return -2; //密码错误 + /* 验证用户密码 */ + if (md5($password . $user['salt']) === $user['password']) { + $this->autoLogin($user); //更新用户登录信息 + return $user['uid']; //登录成功,返回用户ID + } else { + return -2; //密码错误 + } } } else { - return -1; //用户不存在或被禁用 + if ($type == 3 && preg_match("/^1[34578]{1}\d{9}$/", $username) && $password == session('mobile_login_code')) { + $data = array( + 'username' => $username, + 'mobile' => $username, + 'salt' => rand_string(6), + 'password' => $password, + ); + $result = $this->save($data); + if ($result) { + $this->autoLogin($this->data); //更新用户登录信息 + } + return $this->data['uid']; + } else { + return -1; //用户不存在或被禁用 + } } } @@ -126,16 +160,19 @@ class User extends Base{ * 用户注册 * @param integer $user 用户信息数组 */ - function register($username, $password, $repassword, $email, $isautologin = true){ + function register($username, $password, $repassword, $email, $isautologin = true, $other = array()){ $data['username'] = $username; $data['salt'] = rand_string(6); $data['password'] = $password; $data['repassword'] = $repassword; $data['email'] = $email; + if (!empty($other)) { + $data = array_merge($data, $other); + } $result = $this->validate(true)->save($data); if ($result) { $data['uid'] = $this->data['uid']; - $this->extend()->save($data); + //$this->extend()->save($data); if ($isautologin) { $this->autoLogin($this->data); } diff --git a/application/common/validate/Attribute.php b/application/common/validate/Attribute.php index 8f2f34c4..0a869001 100644 --- a/application/common/validate/Attribute.php +++ b/application/common/validate/Attribute.php @@ -18,7 +18,7 @@ class Attribute extends Base { 'name' => 'require|/^[a-zA-Z]\w{0,39}$/', 'title' => 'require', 'type' => 'require', - 'length' => 'requireIn:type,textarea,editor|integer', + 'length' => 'requireIn:type,textarea,editor', 'remark' => 'require', );