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
64bf8a11
Commit
64bf8a11
authored
Oct 19, 2016
by
xiabin
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # src/common/models/Member.php
parents
50c3ef21
dfc202a1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
35 deletions
+47
-35
Member.php
src/common/models/Member.php
+29
-27
Orders.php
src/common/models/Orders.php
+5
-5
MyMemberController.php
src/frontend/controllers/MyMemberController.php
+7
-1
index.php
src/frontend/views/my-member/index.php
+6
-2
No files found.
src/common/models/Member.php
View file @
64bf8a11
...
...
@@ -3,9 +3,7 @@
namespace
common\models
;
use
Yii
;
use
yii\behaviors\TimestampBehavior
;
use
yii\data\Pagination
;
use
yii\db\ActiveRecord
;
/**
* This is the model class for table "member".
...
...
@@ -82,13 +80,13 @@ class Member extends \yii\db\ActiveRecord
* @param null $type 默认为获取全部会员,传入状态获取付费会员或非付费会员
* @return array
*/
public
static
function
getMembersByUserId
(
$userId
,
$page
=
0
,
$num
=
10
,
$type
=
NULL
)
public
static
function
getMembersByUserId
(
$userId
,
$page
=
0
,
$num
=
10
,
$type
=
null
)
{
$where
=
[
'user_id'
=>
$userId
];
$type
!==
NULL
&&
$where
[
'type'
]
=
$type
;
$where
=
[
'user_id'
=>
$userId
];
$type
!==
null
&&
$where
[
'type'
]
=
$type
;
$count
=
self
::
find
()
->
where
(
$where
)
->
count
();
$return
=
[
'count'
=>
$count
,
'data'
=>
[]];
$return
=
[
'count'
=>
$count
,
'data'
=>
[]];
if
(
$page
===
NULL
)
{
$pagination
=
new
Pagination
([
'totalCount'
=>
$count
,
'pageSize'
=>
$num
,
'forcePageParam'
=>
FALSE
]);
...
...
@@ -101,9 +99,9 @@ class Member extends \yii\db\ActiveRecord
if
(
$count
>
0
)
{
$return
[
'data'
]
=
self
::
find
()
->
select
(
'm.id,m.member_id,m.type'
)
->
alias
(
'm'
)
->
where
(
$where
)
->
with
(
'user'
)
->
offset
(
$offset
)
->
limit
(
$num
)
->
orderBy
([
'id'
=>
SORT_DESC
])
->
asArray
()
->
all
();
->
orderBy
([
'id'
=>
SORT_DESC
])
->
asArray
()
->
all
();
}
return
$return
;
}
...
...
@@ -113,7 +111,7 @@ class Member extends \yii\db\ActiveRecord
*/
public
function
getUser
()
{
return
$this
->
hasOne
(
User
::
className
(),
[
'id'
=>
'member_id'
])
->
select
(
'id,username,telephone,role,avatar'
);
return
$this
->
hasOne
(
User
::
className
(),
[
'id'
=>
'member_id'
])
->
select
(
'id,username,telephone,role,avatar'
);
}
/**
...
...
@@ -133,10 +131,10 @@ class Member extends \yii\db\ActiveRecord
//先取出最小订单ID和消费总额
$group
=
Income
::
find
()
->
alias
(
'i'
)
->
select
(
'MIN(i.orders_id) AS min_id, o.user_id, SUM(o.credit) AS credit_total'
)
->
join
(
'LEFT JOIN'
,
Orders
::
tableName
()
.
' o'
,
'o.id=i.orders_id'
)
->
where
([
'i.user_id'
=>
$userId
])
->
andWhere
([
'in'
,
'o.user_id'
,
$memberIds
])
->
join
(
'LEFT JOIN'
,
Orders
::
tableName
()
.
' o'
,
'o.id=i.orders_id'
)
->
where
([
'i.user_id'
=>
$userId
])
->
andWhere
([
'in'
,
'o.user_id'
,
$memberIds
])
->
groupBy
(
'o.user_id'
)
->
asArray
()
->
indexBy
(
'user_id'
)
->
all
();
//再取出订单关联的课程信息
if
(
$group
)
{
$orders
=
Orders
::
find
()
->
select
(
'id,course_id,credit,updated_at'
)
...
...
@@ -144,30 +142,34 @@ class Member extends \yii\db\ActiveRecord
->
asArray
()
->
indexBy
(
'id'
)
->
all
();
foreach
(
$group
as
&
$row
)
{
$row
[
'first_order'
]
=
isset
(
$orders
[
$row
[
'min_id'
]])
?
$orders
[
$row
[
'min_id'
]]
:
NULL
;
$row
[
'first_order'
]
=
isset
(
$orders
[
$row
[
'min_id'
]])
?
$orders
[
$row
[
'min_id'
]]
:
null
;
}
unset
(
$row
);
}
foreach
(
$list
as
&
$row
)
{
$g
=
isset
(
$group
[
$row
[
'member_id'
]])
?
$group
[
$row
[
'member_id'
]]
:
NULL
;
$g
=
isset
(
$group
[
$row
[
'member_id'
]])
?
$group
[
$row
[
'member_id'
]]
:
null
;
$row
[
'credit_total'
]
=
$g
?
$g
[
'credit_total'
]
:
0
;
$row
[
'first_order'
]
=
$g
?
$g
[
'first_order'
]
:
NULL
;
$row
[
'first_order'
]
=
$g
?
$g
[
'first_order'
]
:
null
;
}
}
/**
* 关联成员首个订单
*
* 返回最小order_id,消费总额,以及课程信息
*
* @return $this
*/
public
function
getFirstOrder
()
public
static
function
typeCount
(
$userId
)
{
return
$this
->
hasOne
(
Orders
::
className
(),
[
'id'
=>
'orders_id'
])
->
viaTable
(
Income
::
tableName
(),
[
'user_id'
=>
'user_id'
])
->
with
(
'course'
)
->
select
(
'MIN(id) AS id,credit,course_id'
);
$data
=
self
::
find
()
->
select
(
'COUNT(1) AS count, type'
)
->
where
([
'user_id'
=>
$userId
])
->
groupBy
(
'type'
)
->
asArray
()
->
all
();
$count
=
[
self
::
TYPE_NORMAL
=>
0
,
self
::
TYPE_VIP
=>
0
];
foreach
(
$data
as
$row
)
{
$count
[
$row
[
'type'
]]
=
$row
[
'count'
];
}
return
$count
;
}
}
src/common/models/Orders.php
View file @
64bf8a11
...
...
@@ -5,7 +5,7 @@ namespace common\models;
use
Yii
;
use
yii\behaviors\TimestampBehavior
;
use
yii\data\Pagination
;
use
yii\
redis
\ActiveRecord
;
use
yii\
db
\ActiveRecord
;
/**
* This is the model class for table "orders".
...
...
@@ -20,7 +20,7 @@ use yii\redis\ActiveRecord;
* @property integer $created_at
* @property integer $updated_at
*/
class
Orders
extends
\yii\db\
ActiveRecord
class
Orders
extends
ActiveRecord
{
//订单支付状体
...
...
@@ -137,7 +137,7 @@ class Orders extends \yii\db\ActiveRecord
/**
* 关联课程信息
* @return
$this
* @return
\yii\db\ActiveQuery
*/
public
function
getCourse
()
{
...
...
@@ -146,11 +146,11 @@ class Orders extends \yii\db\ActiveRecord
/**
* 关联课程信息(包括课程的讲师列表)
* @return
$this
* @return
\yii\db\ActiveQuery
*/
public
function
getCourseWithTeachers
()
{
return
$this
->
hasOne
(
Course
::
className
(),
[
'id'
=>
'course_id'
])
->
select
(
'id,user_id,name,price,preview_pic'
)
->
with
(
'teachers'
);
return
$this
->
getCourse
(
)
->
with
(
'teachers'
);
}
}
src/frontend/controllers/MyMemberController.php
View file @
64bf8a11
...
...
@@ -10,6 +10,10 @@ class MyMemberController extends \yii\web\Controller
public
$layout
=
'classCenter'
;
/**
* 我的会员
* @return string
*/
public
function
actionIndex
()
{
$type
=
Yii
::
$app
->
request
->
get
(
'type'
);
...
...
@@ -17,6 +21,8 @@ class MyMemberController extends \yii\web\Controller
$uid
=
Yii
::
$app
->
user
->
getId
();
$typeCount
=
Member
::
typeCount
(
$uid
);
$data
=
Member
::
getMembersByUserId
(
$uid
,
null
,
20
);
//注入订单等信息
...
...
@@ -24,7 +30,7 @@ class MyMemberController extends \yii\web\Controller
Member
::
injectOrderInfo
(
$uid
,
$data
[
'data'
]);
}
return
$this
->
render
(
'index'
,
$data
);
return
$this
->
render
(
'index'
,
$data
+
compact
(
'typeCount'
)
);
}
}
src/frontend/views/my-member/index.php
View file @
64bf8a11
<?php
/**
* @var $this yii\web\View
* @var $typeCount array
* @var $data array
* @var $count int
* @var $pagination \yii\data\Pagination
*/
$this
->
title
=
'我的会员'
;
?>
<div
class=
"vip-top clearfix"
>
<div
class=
"col-md-6"
>
<div
class=
"reg-vip-box"
>
<b>
47
</b>
<b>
<?=
array_sum
(
$typeCount
)
?>
</b>
<span>
全部会员
</span>
<i
class=
"icon-verified_user"
></i>
</div>
</div>
<div
class=
"col-md-6"
>
<div
class=
"money-vip-box"
>
<b>
23
</b>
<b>
<?=
$typeCount
[
\common\models\Member
::
TYPE_VIP
]
?>
</b>
<span>
付费会员
</span>
<i
class=
"icon-heart"
></i>
</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