1、修复bug

2、后台栏目分模型划分
3、前台增加微信开发用户登录功能
This commit is contained in:
2017-08-15 22:09:59 +08:00
parent d6ea6c7e80
commit ded54b79ca
14 changed files with 240 additions and 81 deletions

View File

@@ -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');

View File

@@ -45,6 +45,17 @@
<textarea name="groups" class="form-control">{$info.groups|default=''}</textarea>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">绑定模型</label>
<div class="col-lg-8">
<select name="model_id" class="form-control" style="width: auto;">
<option value="">--请选择--</option>
{volist name="model_list" id="item"}
<option value="{$item['id']}" {if isset($info['model_id']) && $info['model_id'] == $item['id']}selected{/if}>{$item['title']}</option>
{/volist}
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">发布内容</label>
<div class="col-lg-8">

View File

@@ -15,54 +15,68 @@
<div class="main-box-body clearfix">
<!-- 表格列表 -->
<div class="table-responsive clearfix">
<table class="table table-hover">
<thead>
<tr>
<th width="30"><input class="checkbox check-all" type="checkbox"></th>
<th width="60">ID</th>
<th>名称</th>
<th width="120">排序</th>
<th width="120">发布</th>
<th width="120">状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{volist name="tree" id="list"}
<tr>
<td><input class="ids row-selected" type="checkbox" name="id[]" value="{$list.id}"></td>
<td>{$list['id']}</td>
<td>
{$list['level_show']}
<a href="#" class="editable editable-click" data-id="{$list['id']}" data-name="title" data-type="text" data-pk="{$list['id']}" data-url="{:url('editable')}">{$list['title']}</a>
<a class="add-sub-cate" title="添加子分类" href="{:url('add?pid='.$list['id'])}">
<i class="fa fa-plus-square"></i>
</a>
</td>
<td><a href="#" class="editable editable-click" data-id="{$list['id']}" data-name="sort" data-type="text" data-pk="{$list['id']}" data-url="{:url('editable')}">{$list['sort']}</a></td>
<td>{$list['allow_publish']?'是':'否'}</td>
<td>
{if $list['status']}
<span class="label label-primary">启用</span>
{else/}
<span class="label label-danger">禁用</span>
{/if}
</td>
<td>
<a title="编辑" href="{:url('edit?id='.$list['id'].'&pid='.$list['pid'])}">编辑</a>
{if $list['status']}
<a href="{:url('status?id='.$list['id'].'&status=0')}" class="ajax-get">禁用</a>
{else/}
<a href="{:url('status?id='.$list['id'].'&status=1')}" class="ajax-get">启用</a>
{/if}
<a title="删除" href="{:url('remove?id='.$list['id'])}" class="confirm ajax-get">删除</a>
<a title="移动" href="{:url('operate?type=move&from='.$list['id'])}">移动</a>
<a title="合并" href="{:url('operate?type=merge&from='.$list['id'])}">合并</a>
</td>
</tr>
<div class="tabs-wrapper">
<ul class="nav nav-tabs">
<li {if $model_id == ''}class="active"{/if}><a href="{:url('admin/category/index')}">全部</a></li>
{volist name="model_list" id="item"}
<li {if $item['id'] == $model_id}class="active"{/if}>
<a href="{:url('admin/category/index',array('model_id'=>$item['id']))}">{$item['title']}</a>
</li>
{/volist}
</tbody>
</table>
</ul>
<div class="tab-content">
<div class="tab-pane fade in active" id="tab-home">
<table class="table table-hover">
<thead>
<tr>
<th width="30"><input class="checkbox check-all" type="checkbox"></th>
<th width="60">ID</th>
<th>名称</th>
<th width="120">排序</th>
<th width="120">发布</th>
<th width="120">状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{volist name="tree" id="list"}
<tr>
<td><input class="ids row-selected" type="checkbox" name="id[]" value="{$list.id}"></td>
<td>{$list['id']}</td>
<td>
{$list['level_show']}
<a href="#" class="editable editable-click" data-id="{$list['id']}" data-name="title" data-type="text" data-pk="{$list['id']}" data-url="{:url('editable')}">{$list['title']}</a>
<a class="add-sub-cate" title="添加子分类" href="{:url('add?pid='.$list['id'])}">
<i class="fa fa-plus-square"></i>
</a>
</td>
<td><a href="#" class="editable editable-click" data-id="{$list['id']}" data-name="sort" data-type="text" data-pk="{$list['id']}" data-url="{:url('editable')}">{$list['sort']}</a></td>
<td>{$list['allow_publish']?'是':'否'}</td>
<td>
{if $list['status']}
<span class="label label-primary">启用</span>
{else/}
<span class="label label-danger">禁用</span>
{/if}
</td>
<td>
<a title="编辑" href="{:url('edit?id='.$list['id'].'&pid='.$list['pid'])}">编辑</a>
{if $list['status']}
<a href="{:url('status?id='.$list['id'].'&status=0')}" class="ajax-get">禁用</a>
{else/}
<a href="{:url('status?id='.$list['id'].'&status=1')}" class="ajax-get">启用</a>
{/if}
<a title="删除" href="{:url('remove?id='.$list['id'])}" class="confirm ajax-get">删除</a>
<a title="移动" href="{:url('operate?type=move&from='.$list['id'])}">移动</a>
<a title="合并" href="{:url('operate?type=merge&from='.$list['id'])}">合并</a>
</td>
</tr>
{/volist}
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- /表格列表 -->
</div>

View File

@@ -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() {

View File

@@ -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;

View File

@@ -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('没有指定插件名称,控制器或操作!');
}

View File

@@ -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);
}
}
//当前栏目导航

View File

@@ -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() {

View File

@@ -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'];

View File

@@ -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',

View File

@@ -14,4 +14,8 @@ namespace app\common\model;
*/
class Content extends BaseModel{
protected $type = array(
'create_time' => 'integer',
'update_time' => 'integer',
);
}

View File

@@ -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']) {

View File

@@ -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);
}

View File

@@ -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',
);