Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zuiketang
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
zuiketang
Commits
f16822b1
Commit
f16822b1
authored
Oct 17, 2016
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
课堂概况显示各种信息
parent
f5dc8573
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
82 additions
and
18 deletions
+82
-18
Course.php
src/common/models/Course.php
+29
-0
Income.php
src/common/models/Income.php
+19
-8
ClassesInfoController.php
src/frontend/controllers/ClassesInfoController.php
+23
-4
index.php
src/frontend/views/classes-info/index.php
+10
-5
index.php
src/frontend/views/my-member/index.php
+1
-1
No files found.
src/common/models/Course.php
View file @
f16822b1
...
...
@@ -189,4 +189,33 @@ class Course extends \yii\db\ActiveRecord
{
return
$this
->
hasOne
(
User
::
className
(),
[
'id'
=>
'user_id'
])
->
select
(
'id,username,role,avatar'
);;
}
/**
* 统计指定用户发布的课程数量
*
* @param int $userId
* @param int $status 默认只统计审核通过的,设为 null 则统计全部
* @return int
*/
public
static
function
countCourseByUserId
(
$userId
,
$status
=
self
::
STATUS_OK
)
{
$where
=
[
'user_id'
=>
$userId
];
$status
!==
null
&&
$where
[
'status'
]
=
$status
;
return
self
::
find
()
->
where
(
$where
)
->
count
();
}
/**
* 统计指定用户发布课程的评论总数
*
* @param int $userId
* @param int $status 默认只统计审核通过的课程评论,设为 null 则统计全部
* @return int
*/
public
static
function
countCommentsByUserId
(
$userId
,
$status
=
self
::
STATUS_OK
)
{
$where
=
[
'user_id'
=>
$userId
];
$status
!==
null
&&
$where
[
'status'
]
=
$status
;
return
self
::
find
()
->
where
(
$where
)
->
sum
(
'comment_count'
);
}
}
src/common/models/Income.php
View file @
f16822b1
...
...
@@ -75,6 +75,7 @@ class Income extends \yii\db\ActiveRecord
}
/**
* 关联订单详细数据
* @return $this
*/
public
function
getOrder
()
...
...
@@ -82,12 +83,6 @@ class Income extends \yii\db\ActiveRecord
return
$this
->
hasOne
(
Orders
::
className
(),
[
'id'
=>
'orders_id'
])
->
with
(
'user'
)
->
with
(
'course'
);
}
//public function getUser()
//{
// return $this->hasOne(User::className(), ['id'=>'user_id'])->viaTable(Orders::tableName(), ['id'=>'orders_id'])
// ->select('id,username,role,avatar');
//}
/**
* 获取指定用户已出售课程的订单列表
*
...
...
@@ -132,9 +127,25 @@ class Income extends \yii\db\ActiveRecord
$where
=
[
'i.user_id'
=>
$userId
];
$status
!==
null
&&
$where
[
'i.status'
]
=
$status
;
return
(
float
)
self
::
find
()
->
alias
(
'i'
)
->
select
(
'SUM(o.credit)'
)
->
where
(
$where
)
return
(
float
)
self
::
find
()
->
alias
(
'i'
)
->
where
(
$where
)
->
join
(
'LEFT JOIN'
,
Orders
::
tableName
()
.
' o'
,
'o.id=i.orders_id'
)
->
sum
(
'o.credit'
);
}
/**
* 统计指定用户时间范围内的收入
*
* @param int $userId
* @param int $timeBetween 起始时间戳
* @param int $timeAnd 结束时间戳
* @return float
*/
public
static
function
getMoneyTotalByTime
(
$userId
,
$timeBetween
,
$timeAnd
)
{
return
(
float
)
self
::
find
()
->
alias
(
'i'
)
->
join
(
'LEFT JOIN'
,
Orders
::
tableName
()
.
' o'
,
'o.id=i.orders_id'
)
->
scalar
();
->
where
([
'i.user_id'
=>
$userId
])
->
andWhere
([
'between'
,
'i.updated_at'
,
$timeBetween
,
$timeAnd
])
->
sum
(
'o.credit'
);
}
}
src/frontend/controllers/ClassesInfoController.php
View file @
f16822b1
...
...
@@ -3,6 +3,8 @@
namespace
frontend\controllers
;
use
common\models\Classes
;
use
common\models\Course
;
use
common\models\Income
;
use
frontend\components\ClassesFilter
;
use
Yii
;
use
yii\filters\AccessControl
;
...
...
@@ -36,10 +38,29 @@ class ClassesInfoController extends \yii\web\Controller
];
}
/**
* 课堂概况
* @return string
*/
public
function
actionIndex
()
{
$uid
=
Yii
::
$app
->
user
->
getId
();
//课堂信息
$model
=
Classes
::
findOne
(
$this
->
classStatus
[
'id'
]);
return
$this
->
render
(
'index'
,
compact
(
'model'
));
//统计课程数量
$courseCount
=
Course
::
countCourseByUserId
(
$uid
);
//统计今日收
$timeBetween
=
strtotime
(
'Today'
);
$timeAnd
=
strtotime
(
'Tomorrow'
)
-
1
;
$todayIncome
=
Income
::
getMoneyTotalByTime
(
$uid
,
$timeBetween
,
$timeAnd
);
//统计评论数量
$commentCount
=
Course
::
countCommentsByUserId
(
$uid
);
return
$this
->
render
(
'index'
,
compact
(
'model'
,
'courseCount'
,
'todayIncome'
,
'commentCount'
));
}
/**
...
...
@@ -60,9 +81,7 @@ class ClassesInfoController extends \yii\web\Controller
}
else
{
$agreement
=
1
;
}
echo
$model
->
status
;
if
(
Yii
::
$app
->
request
->
getIsPost
())
{
$model
->
load
(
Yii
::
$app
->
request
->
post
());
$model
->
user_id
=
Yii
::
$app
->
user
->
getId
();
...
...
src/frontend/views/classes-info/index.php
View file @
f16822b1
...
...
@@ -2,26 +2,31 @@
/**
* @var $this yii\web\View
* @var \common\models\Classes $model
* @var $courseCount int
* @var $todayIncome float
* @var $commentCount int
*/
use
yii\helpers\Url
;
$this
->
title
=
'我的课堂'
;
?>
<div
class=
"class-name"
>
<?=
$model
->
name
?>
</div>
<div
class=
"class-intro"
>
<div
class=
"col-md-4"
>
<h3>
课程总数
</h3>
<p>
10
<small>
讲
</small></p>
<a
href=
"
#
"
>
发布课程
</a>
<p>
<?=
$courseCount
?>
<small>
讲
</small></p>
<a
href=
"
<?=
Url
::
to
([
'my-course/publish'
])
?>
"
>
发布课程
</a>
<i
class=
"icon-play"
></i>
</div>
<div
class=
"col-md-4"
>
<h3>
今日收益
</h3>
<p>
192.00
<small>
元
</small></p>
<a
href=
"
#
"
>
查看账单
</a>
<p>
<?=
$todayIncome
?>
<small>
元
</small></p>
<a
href=
"
<?=
Url
::
to
([
'my-income/index'
])
?>
"
>
查看账单
</a>
<i
class=
"icon-clipboard"
></i>
</div>
<div
class=
"col-md-4"
>
<h3>
今日发言
</h3>
<p>
891
<small>
条
</small></p>
<p>
<?=
$commentCount
?>
<small>
条
</small></p>
<i
class=
"icon-speech-bubble"
></i>
</div>
</div>
\ No newline at end of file
src/frontend/views/my-member/index.php
View file @
f16822b1
<?php
/* @var $this yii\web\View */
?>
<div
class=
"vip-top"
>
<div
class=
"vip-top
clearfix
"
>
<div
class=
"col-md-6"
>
<div
class=
"reg-vip-box"
>
<b>
47
</b>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment