初始化项目

This commit is contained in:
2016-06-21 17:12:08 +08:00
commit 7ea154d684
903 changed files with 226100 additions and 0 deletions

View File

@@ -0,0 +1,184 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\user\controller;
use app\common\controller\User;
class Content extends User{
public function _initialize(){
parent::_initialize();
$this->getContentMenu();
$model_id = $this->request->param('model_id');
$row = db('Model')->select();
foreach ($row as $key => $value) {
$list[$value['id']] = $value;
}
if (empty($list[$model_id])) {
return $this->error("无此模型!");
}else {
$this->modelInfo = $list[$model_id];
if ($this->modelInfo['extend'] > 1) {
$this->model = model($this->modelInfo['name']);
}else{
$this->model = model('Document')->extend($this->modelInfo['name']);
}
}
$this->assign('model_id',$model_id);
$this->assign('model_list',$list);
$this->assign('model_info',$this->modelInfo);
}
public function index(){
if ($this->modelInfo['list_grid'] == '') {
return $this->error("列表定义不正确!", url('admin/model/edit',array('id'=>$this->modelInfo['id'])));
}
$grid_list = get_grid_list($this->modelInfo['list_grid']);
$order = "id desc";
$map['uid'] = session('user_auth.uid');
if ($this->modelInfo['extend'] == 1) {
$map['model_id'] = $this->modelInfo['id'];
}
$field = array_filter($grid_list['fields']);
$list = $this->model->where($map)->field($field)->order($order)->paginate(15);
$data = array(
'grid' => $grid_list,
'list' => $list,
'page' => $list->render()
);
$this->assign($data);
return $this->fetch();
}
/**
* 内容添加
* @author molong <ycgpp@126.com>
*/
public function add(){
if (IS_POST) {
$result = $this->model->change();
if ($result) {
return $this->success("添加成功!",url('admin/content/index',array('model_id'=>$this->modelInfo['id'])));
}else{
return $this->error($this->model->getError(),'');
}
}else{
$info = array(
'model_id' => $this->modelInfo['id']
);
$data = array(
'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo)
);
$this->assign($data);
return $this->fetch('public/edit');
}
}
/**
* 内容修改
* @author molong <ycgpp@126.com>
*/
public function edit($id){
if (IS_POST) {
$result = $this->model->change();
if ($result !== false) {
return $this->success("更新成功!",url('admin/content/index',array('model_id'=>$this->modelInfo['id'])));
}else{
return $this->error($this->model->getError(),'');
}
}else{
if (!$id) {
return $this->error("非法操作!");
}
$info = $this->model->detail($id);
if (!$info) {
return $this->error($this->model->getError());
}
$info['model_id'] = $this->modelInfo['id'];
$data = array(
'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo)
);
$this->assign($data);
return $this->fetch('public/edit');
}
}
/**
* 内容删除
* @author molong <ycgpp@126.com>
*/
public function del(){
$id = input('get.id','','trim');
$ids = input('post.ids/a',array());
array_push($ids, $id);
if (empty($ids)) {
return $this->error("非法操作!");
}
$map['id'] = array('IN',$ids);
$result = $this->model->del($map);
if ($result) {
return $this->success("删除成功!");
}else{
return $this->error("删除失败!", '', "");
}
}
protected function getField(){
$field_group = parse_config_attr($this->modelInfo['field_group']);
$field_sort = json_decode($this->modelInfo['field_sort'],true);
if ($this->modelInfo['extend'] > 1) {
$map['model_id'] = $this->modelInfo['id'];
}else{
$model_id[] = $this->modelInfo['id'];
$model_id[] = 1;
$map['model_id'] = array('IN',$model_id);
}
if (ACTION_NAME == 'add') {
$map['is_show'] = array('in',array('1','2'));
}elseif(ACTION_NAME == 'edit'){
$map['is_show'] = array('in',array('1','3'));
}
//获得数组的第一条数组
$first_key = array_keys($field_group);
$fields = model('Attribute')->getFieldlist($map);
if (!empty($field_sort)) {
foreach ($field_sort as $key => $value) {
foreach ($value as $index) {
if (isset($fields[$index])) {
$groupfield[$key][] = $fields[$index];
unset($fields[$index]);
}
}
}
}
//未进行排序的放入第一组中
$fields[] = array('name'=>'model_id','type'=>'hidden'); //加入模型ID值
$fields[] = array('name'=>'id','type'=>'hidden'); //加入模型ID值
foreach ($fields as $key => $value) {
$groupfield[$first_key[0]][] = $value;
}
foreach ($field_group as $key => $value) {
if ($groupfield[$key]) {
$data[$value] = $groupfield[$key];
}
}
return $data;
}
}

View File

@@ -0,0 +1,18 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\user\controller;
use app\common\controller\User;
class Index extends User{
public function index(){
return $this->fetch();
}
}

View File

@@ -0,0 +1,74 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\user\controller;
use app\common\controller\Fornt;
class Login extends Fornt{
public function index($username = '', $password = '', $verify = ''){
if (IS_POST) {
if (!$username || !$password) {
return $this->error('用户名或者密码不能为空!','');
}
//验证码验证
$this->checkVerify($verify);
$user = model('User');
$uid = $user->login($username,$password);
if ($uid > 0) {
$url = session('http_referer') ? session('http_referer') : url('user/index/index');
return $this->success('登录成功!', $url);
}else{
switch($uid) {
case -1: $error = '用户不存在或被禁用!'; break; //系统级别禁用
case -2: $error = '密码错误!'; break;
default: $error = '未知错误!'; break; // 0-接口参数错误(调试阶段使用)
}
return $this->error($error,'');
}
}else{
session('http_referer', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
if (is_login()) {
return $this->redirect('user/index/index');
}else{
return $this->fetch();
}
}
}
public function logout(){
model('User')->logout();
return $this->redirect('index/index/index');
}
public function register(){
if (IS_POST) {
$user = model('User');
$username = input('username', '', 'trim');
$password = input('password', '', 'trim');
$repassword = input('repassword', '', 'trim');
$verify = input('verify', '', 'trim');
//验证码验证
$this->checkVerify($verify);
if ($username == '' || $password == '' || $repassword == '') {
return $this->error("请填写完整注册信息!", '');
}
$result = $user->register($username, $password, $repassword);
if ($result) {
return $this->success('注册成功!', url('user/index/index'));
}else{
return $this->error($user->getError(), '');
}
}else{
return $this->fetch();
}
}
}

View File

@@ -0,0 +1,57 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\user\controller;
use app\common\controller\User;
class Profile extends User{
//修改资料
public function index(){
$user = model('User');
if (IS_POST) {
$result = $user->change();
if ($result !== false) {
return $this->success("更新成功!", "");
}else{
return $this->error($user->getError(), '');
}
}else{
$group['基础资料'] = $user->useredit;
$info = $user->getInfo(session('user_auth.uid'));
$data = array(
'fieldGroup' => $group,
'info' => $info
);
$this->assign($data);
return $this->fetch('public/edit');
}
}
//修改密码
public function editpw(){
$user = model('User');
if (IS_POST) {
$result = $user->editpw();
if ($result !== false) {
return $this->success("更新成功!", "");
}else{
return $this->error($user->getError(), '');
}
}else{
return $this->fetch();
}
}
//修改头像
public function avatar(){
return $this->fetch();
}
}

View File

@@ -0,0 +1,75 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\user\controller;
use app\common\controller\User;
class Upload extends User {
protected $controller;
public function _initialize(){
parent::_initialize();
$this->controller = controller('common/Upload');
}
public function _empty(){
$action = $this->request->action();
return $this->controller->$action();
}
public function download(){
$order_id = input('order_id', '', 'trim');
$product_id = input('product_id', '', 'trim');
//判断是否已经支付
$pay_status = db('Order')->where(array('id'=>$order_id))->value('pay_status');
if (!$pay_status) {
return $this->error("您还未购买!");
}
//获取产品文件
$book = db('Book')->where(array('id'=>$product_id))->find();
if (!$book['file']) {
return $this->error("无此图书文件,请联系网站管理员!");
}
$book_file = db('file')->where(array('id'=>$book['file']))->find();
$attachment = config('attachment_upload');
$file = array(
'rootpath' => $attachment['rootPath'],
'savepath' => $book_file['savepath'],
'savename' => $book_file['savename'],
'type' => $book_file['ext'],
'size' => $book_file['size'],
'name' => $book['book_name'].'.'.$book_file['ext']
);
$result = $this->controller->downLocalFile($file);
if ($result === false) {
return $this->error("下载失败!");
}
}
public function avatar(){
$file = \think\Input::file('UpFile');
$info = $file->rule('uniqid')->move('./uploads/avatar/'.setavatardir(session('user_auth.uid')), true, true);
$image = new \org\Image();
$image->init()->open($info->getPathname())->thumb(120,120)->save('./uploads/avatar/'.setavatardir(session('user_auth.uid')).'/avatar_big.png');
$image->init()->open($info->getPathname())->thumb(100,100)->save('./uploads/avatar/'.setavatardir(session('user_auth.uid')).'/avatar_middle.png');
$image->init()->open($info->getPathname())->thumb(60,60)->save('./uploads/avatar/'.setavatardir(session('user_auth.uid')).'/avatar_small.png');
unlink($info->getPathname());
$data = array(
array('ImgUrl' => '/uploads/avatar/'.setavatardir(session('user_auth.uid')).'/avatar_big.png'),
array('ImgUrl' => '/uploads/avatar/'.setavatardir(session('user_auth.uid')).'/avatar_middle.png'),
array('ImgUrl' => '/uploads/avatar/'.setavatardir(session('user_auth.uid')).'/avatar_small.png'),
);
return json_encode($data);
}
}