Skip to content

Commit

Permalink
添加个人中心模块,优化部分功能
Browse files Browse the repository at this point in the history
  • Loading branch information
周先生 authored and 周先生 committed Dec 31, 2017
1 parent fcae464 commit d80272c
Show file tree
Hide file tree
Showing 21 changed files with 745 additions and 234 deletions.
2 changes: 1 addition & 1 deletion app/Config/common.php
Expand Up @@ -8,7 +8,7 @@

return new \Phalcon\Config([
'login_type' => [
1
1,2
],
/**
* 七牛上传配置信息
Expand Down
2 changes: 1 addition & 1 deletion app/Config/config.php
Expand Up @@ -38,7 +38,7 @@
// This allows the baseUri to be understand project paths that are not in the root directory
// of the webpspace. This will break if the public/index.php entry point is moved or
// possibly if the web server rewrite rules are changed. This can also be set to a static path.
'baseUri' => "{$_SERVER['REQUEST_SCHEME']}://{$_SERVER['HTTP_HOST']}"
'baseUri' => !empty($_SERVER['REQUEST_SCHEME']) && !empty($_SERVER['HTTP_HOST']) ? "{$_SERVER['REQUEST_SCHEME']}://{$_SERVER['HTTP_HOST']}" : ""
],
/** 默认控制器和方法 */
'baseController' => 'home',
Expand Down
9 changes: 7 additions & 2 deletions app/Controllers/BaseController.php
Expand Up @@ -3,6 +3,7 @@
namespace App\Controllers;

use App\Models\ForumUser;
use App\Services\ReplyService;
use Phalcon\Mvc\Controller;

class BaseController extends Controller
Expand All @@ -11,11 +12,15 @@ class BaseController extends Controller

public function onConstruct()
{
$this->user = $this->session->get('user') ?: ForumUser::findFirst('id = 11 AND status = 1')->toArray();
//$this->user = $this->session->get('user');
//$this->user = $this->session->get('user') ?: ForumUser::findFirst('id = 11 AND status = 1')->toArray();
$this->user = $this->session->get('user');
$this->view->local_user = $this->user;
$this->view->verify_title = $this->commonConfig->verify_title->toArray();
$this->view->login_type = json_encode($this->commonConfig->login_type->toArray());
if($this->user){
$this->view->is_has_new_msg = ReplyService::hasNewMessage($this->user, 1) ?: ReplyService::hasNewMessage($this->user, 2);
}

}

/**
Expand Down
82 changes: 82 additions & 0 deletions app/Controllers/User/AttentionController.php
Expand Up @@ -9,8 +9,10 @@
namespace App\Controllers\User;

use App\Controllers\BaseController;
use App\Models\ForumArticleInfo;
use App\Models\ForumUserAttention;
use App\Models\ForumUserCollection;
use App\Services\ArticleInfoService;

class AttentionController extends BaseController
{
Expand Down Expand Up @@ -104,6 +106,86 @@ public function setAttentionAction()
output_data(1, '操作成功', ['status' => $attentionModel->status]);
}

public function dynamicAction()
{
if (!$this->request->isPost()) {
output_data(-502, '非法请求');
}
if (!$this->user) {
output_data(-401, '请先登录');
}
$page = $this->request->getPost('current_page', 'int', 1);
$pageNums = $this->request->getPost('page_nums', 'int', 20);
$res = ArticleInfoService::getAttentionArticle($this->user,$page,$pageNums);
$arr = [];
$titles = $this->commonConfig->verify_title->toArray();
foreach ($res['rows'] as $key=>$value){
$arr[$key] = [
'user_id'=>$value->articleUserInfo->id,
'id'=>$value->id,
'title'=>$value->title,
'nickname'=>$value->articleUserInfo->nickname,
'head_img'=>$value->articleUserInfo->head_img,
'verify_type'=>$value->articleUserInfo->verify_type,
'type_name' => !empty($titles[$value->articleUserInfo->verify_type]) ? $titles[$value->articleUserInfo->verify_type] : '',
'time' => date('Y-m-d H:i',$value->created_time)." ".timeCompute($value->created_time),
];
}
$res['rows'] = $arr;
output_data(1, 'success', $res);
}

/**
* 我的关注用户列表接口
*/
public function myAttentionListAction()
{
if (!$this->request->isPost()) {
output_data(-502, '非法请求');
}

if (!$this->user) {
output_data(-401, '请先登录');
}
$page = $this->request->getPost('current_page', 'int', 1);
$pageNums = $this->request->getPost('page_nums', 'int', 20);

$conditions = "user_id = :user_id: AND status = :status:";
$bind = ['user_id' => $this->user['id'], 'status' => 1];
$data = ForumUserAttention::find([
"conditions" => $conditions,
"bind" => $bind,
'order' => "id DESC",
'columns' => '*',
'limit' => $pageNums,
'offset' => ($page - 1) * $pageNums,
]);
$arr = [];
$titles = $this->commonConfig->verify_title->toArray();
foreach ($data as $key => $value) {
$arr[$key] = [
'id' => $value->id,
'user_id' => $value->userInfo->id,
'attention_user_id' => $value->attention_user_id,
'nickname' => $value->userInfo->nickname,
'head_img' => $value->userInfo->head_img,
'verify_type' => $value->userInfo->verify_type,
'type_name' => !empty($titles[$value->userInfo->verify_type]) ? $titles[$value->userInfo->verify_type] : '',
'time' => timeCompute($value->created_time),
];
}

$count = ForumUserAttention::count([
"conditions" => $conditions,
"bind" => $bind
]);
$result = [
'rows' => $arr,
'count' => $count,
'max_page' => (int)ceil($count / $pageNums)
];
output_data(1, 'success', $result);
}


}
12 changes: 10 additions & 2 deletions app/Controllers/User/MyController.php
Expand Up @@ -12,8 +12,10 @@
use App\Models\ForumArticleInfo;
use App\Models\ForumArticleReply;
use App\Models\ForumUser;
use App\Models\ForumUserAttention;
use App\Models\ForumUserCollection;
use App\Services\ArticleInfoService;
use App\Services\ReplyService;

class MyController extends BaseController
{
Expand Down Expand Up @@ -48,6 +50,12 @@ public function indexAction()
public function messageAction()
{
$this->view->user_menu_choose = 'message';
$reply_res = ReplyService::getMyArticleReply($this->user, 1, 15, 2);
$at_reply_res = ReplyService::getAtMeReply($this->user, 1, 15, 2);
$this->view->reply_nums = $reply_res['count'];
$this->view->at_nums = $at_reply_res['count'];
$this->view->reply_new_nums = ReplyService::hasNewMessage($this->user, 1);
$this->view->at_new_nums = ReplyService::hasNewMessage($this->user, 2);
$this->view->render("user", "message");
}

Expand Down Expand Up @@ -75,11 +83,11 @@ public function articleAction($type = 0)
public function attentionAction()
{
$this->view->user_menu_choose = 'attention';
$this->view->article_nums = ForumArticleInfo::count([
$this->view->dynamic_nums = ForumArticleInfo::count([
'conditions' => 'user_id = :user_id: AND status = :status:',
'bind' => ['user_id' => $this->user['id'], 'status' => 1]
]);
$this->view->collection_nums = ForumUserCollection::count([
$this->view->attention_nums = ForumUserAttention::count([
'conditions' => 'user_id = :user_id: AND status = :status:',
'bind' => ['user_id' => $this->user['id'], 'status' => 1]
]);
Expand Down
120 changes: 120 additions & 0 deletions app/Controllers/User/ReplyController.php
@@ -0,0 +1,120 @@
<?php
/**
* Created by PhpStorm.
* User: Mr.Zhou
* Date: 2017/12/9
* Time: 下午2:52
*/

namespace App\Controllers\User;

use App\Controllers\BaseController;
use App\Models\ForumArticleInfo;
use App\Models\ForumArticleReply;
use App\Models\ForumArticleReplyView;
use App\Models\ForumUserAttention;
use App\Models\ForumUserCollection;
use App\Services\ArticleInfoService;
use App\Services\ReplyService;

class ReplyController extends BaseController
{
public function initialize()
{

}

public function setReadMsgAction()
{
if (!$this->request->isPost()) {
output_data(-502, '非法请求');
}
if (!$this->user) {
output_data(-401, '请先登录');
}
$type = $this->request->getPost('type', 'int',1);

$readModel = new ForumArticleReplyView();
$flag = $readModel->create([
'type' => $type,
'user_id' => $this->user['id'],
'created_time' => time(),
]);
if ($flag) {
output_data(1, 'success');
}
output_data(-1, '信息阅读失败');
}

/**
* 获取回复列表接口
*/
public function myReplyListAction()
{
if (!$this->request->isPost()) {
output_data(-502, '非法请求');
}
if (!$this->user) {
output_data(-401, '请先登录');
}

$page = $this->request->getPost('current_page', 'int', 1);
$pageNums = $this->request->getPost('page_nums', 'int', 20);

$res = ReplyService::getMyArticleReply($this->user, $page, $pageNums);
$arr = [];
$titles = $this->commonConfig->verify_title->toArray();
foreach ($res['rows'] as $key => $value) {
$arr[$key] = [
'article_id' => $value->article_id,
'user_id' => $value->user_id,
'content' => $value->content,
'title' => $value->articleInfo->title,
'nickname' => $value->userInfo->nickname,
'head_img' => $value->userInfo->head_img,
'verify_type' => $value->userInfo->verify_type,
'type_name' => !empty($titles[$value->userInfo->verify_type]) ? $titles[$value->userInfo->verify_type] : '',
'time' => timeCompute($value->created_time),
];
}
$res['rows'] = $arr;
output_data(1, 'success', $res);
}

/**
* 获取@我的回复列表接口
*/
public function atMeListAction()
{
if (!$this->request->isPost()) {
output_data(-502, '非法请求');
}
if (!$this->user) {
output_data(-401, '请先登录');
}

$page = $this->request->getPost('current_page', 'int', 1);
$pageNums = $this->request->getPost('page_nums', 'int', 20);

$res = ReplyService::getAtMeReply($this->user, $page, $pageNums);
$arr = [];
$titles = $this->commonConfig->verify_title->toArray();
foreach ($res['rows'] as $key => $value) {
$arr[$key] = [
'article_id' => $value->article_id,
'user_id' => $value->user_id,
'content' => $value->content,
'title' => $value->articleInfo->title,
'nickname' => $value->userInfo->nickname,
'head_img' => $value->userInfo->head_img,
'verify_type' => $value->userInfo->verify_type,
'type_name' => !empty($titles[$value->userInfo->verify_type]) ? $titles[$value->userInfo->verify_type] : '',
'time' => timeCompute($value->created_time),
];
}
$res['rows'] = $arr;
output_data(1, 'success', $res);
}


}
78 changes: 78 additions & 0 deletions app/Models/ForumArticleReplyView.php
@@ -0,0 +1,78 @@
<?php

namespace App\Models;

class ForumArticleReplyView extends BaseModel
{

/**
*
* @var integer
* @Primary
* @Identity
* @Column(type="integer", length=11, nullable=false)
*/
public $id;

/**
*
* @var integer
* @Column(type="integer", length=4, nullable=false)
*/
public $type;

/**
*
* @var integer
* @Column(type="integer", length=11, nullable=false)
*/
public $user_id;

/**
*
* @var integer
* @Column(type="integer", length=11, nullable=false)
*/
public $created_time;

/**
* Initialize method for model.
*/
public function initialize()
{
$this->setSchema("phalcon-forum");
}

/**
* Returns table name mapped in the model.
*
* @return string
*/
public function getSource()
{
return 'forum_article_reply_view';
}

/**
* Allows to query a set of records that match the specified conditions
*
* @param mixed $parameters
* @return ForumArticleReplyView[]|ForumArticleReplyView|\Phalcon\Mvc\Model\ResultSetInterface
*/
public static function find($parameters = null)
{
return parent::find($parameters);
}

/**
* Allows to query the first record that match the specified conditions
*
* @param mixed $parameters
* @return ForumArticleReplyView|\Phalcon\Mvc\Model\ResultInterface
*/
public static function findFirst($parameters = null)
{
return parent::findFirst($parameters);
}

}
6 changes: 6 additions & 0 deletions app/Models/ForumUserAttention.php
Expand Up @@ -55,6 +55,12 @@ class ForumUserAttention extends BaseModel
public function initialize()
{
$this->setSchema("phalcon-forum");
$this->hasOne(
"attention_user_id",
"App\\Models\\ForumUser",
"id",
['alias' => 'userInfo']
);
}

/**
Expand Down

0 comments on commit d80272c

Please sign in to comment.