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
50d71546
Commit
50d71546
authored
Oct 17, 2016
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
已售课程订单显示已结算/未结算的资金
parent
693d0b1e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
7 deletions
+50
-7
Income.php
src/common/models/Income.php
+28
-2
Orders.php
src/common/models/Orders.php
+13
-1
MyIncomeController.php
src/frontend/controllers/MyIncomeController.php
+7
-2
index.php
src/frontend/views/my-income/index.php
+2
-2
No files found.
src/common/models/Income.php
View file @
50d71546
...
...
@@ -85,10 +85,19 @@ class Income extends \yii\db\ActiveRecord
// ->select('id,username,role,avatar');
//}
public
static
function
getIncomeListByUserId
(
$userId
,
$page
=
0
,
$num
=
10
,
$status
=
self
::
STATUS_NOT_SETTLED
)
/**
* 获取指定用户已出售课程的订单列表
*
* @param int $userId
* @param int $page 页数,默认0为第1页,传null则使用系统自动分页
* @param int $num 每页数量
* @param int $status 要获取的状态,默认为全部
* @return array
*/
public
static
function
getIncomeListByUserId
(
$userId
,
$page
=
0
,
$num
=
10
,
$status
=
null
)
{
$where
=
[
'user_id'
=>
$userId
];
$status
!=
null
&&
$where
[
'status'
]
=
$status
;
$status
!=
=
null
&&
$where
[
'status'
]
=
$status
;
$count
=
self
::
find
()
->
where
(
$where
)
->
count
();
$return
=
[
'count'
=>
$count
,
'data'
=>
[]];
...
...
@@ -108,4 +117,21 @@ class Income extends \yii\db\ActiveRecord
return
$return
;
}
/**
* 获取售出课程订单的资金统计
*
* @param int $userId
* @param int $status
* @return float
*/
public
static
function
getMoneyTotal
(
$userId
,
$status
=
null
)
{
$where
=
[
'i.user_id'
=>
$userId
];
$status
!==
null
&&
$where
[
'i.status'
]
=
$status
;
return
(
float
)
self
::
find
()
->
alias
(
'i'
)
->
select
(
'SUM(o.credit)'
)
->
where
(
$where
)
->
join
(
'LEFT JOIN'
,
Orders
::
tableName
()
.
' o'
,
'o.id=i.orders_id'
)
->
scalar
();
}
}
src/common/models/Orders.php
View file @
50d71546
...
...
@@ -119,17 +119,29 @@ class Orders extends \yii\db\ActiveRecord
':course_id'
=>
$courseId
])
->
one
();
}
/**
* 关联下单用户信息
* @return $this
*/
public
function
getUser
()
{
return
$this
->
hasOne
(
User
::
className
(),
[
'id'
=>
'user_id'
])
->
select
(
'id,username,telephone,role,avatar'
);
}
/**
* 关联课程信息
* @return $this
*/
public
function
getCourse
()
{
return
$this
->
hasOne
(
Course
::
className
(),
[
'id'
=>
'course_id'
])
->
select
(
'id,user_id,name,price,preview_pic'
);
}
/**
* 关联课程信息(包括课程的讲师列表)
* @return $this
*/
public
function
getCourseWithTeachers
()
{
return
$this
->
hasOne
(
Course
::
className
(),
[
'id'
=>
'course_id'
])
->
select
(
'id,user_id,name,price,preview_pic'
)
->
with
(
'teachers'
);
...
...
src/frontend/controllers/MyIncomeController.php
View file @
50d71546
...
...
@@ -16,8 +16,13 @@ class MyIncomeController extends \yii\web\Controller
*/
public
function
actionIndex
()
{
$ret
=
Income
::
getIncomeListByUserId
(
Yii
::
$app
->
user
->
getId
(),
null
,
20
);
return
$this
->
render
(
'index'
,
$ret
);
$uid
=
Yii
::
$app
->
user
->
getId
();
$ret
=
Income
::
getIncomeListByUserId
(
$uid
,
null
,
20
);
$settled
=
Income
::
getMoneyTotal
(
$uid
,
Income
::
STATUS_IS_SETTLED
);
$notSettled
=
Income
::
getMoneyTotal
(
$uid
,
Income
::
STATUS_NOT_SETTLED
);
return
$this
->
render
(
'index'
,
$ret
+
compact
(
'settled'
,
'notSettled'
));
}
}
src/frontend/views/my-income/index.php
View file @
50d71546
...
...
@@ -10,11 +10,11 @@ $this->title = '知识有价';
</div>
<div
class=
"col-md-4"
>
<h3>
已结算
</h3>
<p>
¥
162.03
</p>
<p>
¥
<?=
$settled
?>
</p>
</div>
<div
class=
"col-md-4"
>
<h3>
待结算
</h3>
<p>
¥
1829.00
</p>
<p>
¥
<?=
$notSettled
?>
</p>
</div>
</div>
...
...
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