Commit 83b50089 authored by 杨培's avatar 杨培

知识有价列表

parent 520e6928
......@@ -4,6 +4,7 @@ namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\data\Pagination;
use yii\redis\ActiveRecord;
/**
......@@ -18,6 +19,10 @@ use yii\redis\ActiveRecord;
*/
class Income extends \yii\db\ActiveRecord
{
const STATUS_NOT_SETTLED = 0; //未结算状态
const STATUS_IS_SETTLED = 1; //已结算状态
/**
* @inheritdoc
*/
......@@ -68,4 +73,39 @@ class Income extends \yii\db\ActiveRecord
'updated_at' => 'Updated At',
];
}
public function getOrder()
{
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');
//}
public static function getIncomeListByUserId($userId, $page=0, $num=10, $status=self::STATUS_NOT_SETTLED)
{
$where = ['user_id'=>$userId];
$status != null && $where['status'] = $status;
$count = self::find()->where($where)->count();
$return = ['count'=>$count, 'data' =>[]];
if ($page === null) {
$pagination = new Pagination(['totalCount' => $count, 'pageSize'=>$num, 'forcePageParam'=>false]);
$offset = $pagination->offset;
$return['pagination'] = $pagination;
} else {
$offset = $page * $num;
}
if ($count > 0) {
$return['data'] = self::find()->where($where)->offset($offset)->limit($num)->with('order')->asArray()->all();
}
return $return;
}
}
......@@ -119,6 +119,15 @@ class Orders extends \yii\db\ActiveRecord
':course_id' => $courseId
])->one();
}
public function getUser()
{
return $this->hasOne(User::className(), ['id'=>'user_id'])->select('id,username,role,avatar');
}
public function getCourse()
{
return $this->hasOne(Course::className(), ['id'=>'course_id'])->select('id,user_id,name,price,preview_pic');
}
}
......@@ -2,6 +2,9 @@
namespace frontend\controllers;
use common\models\Income;
use Yii;
class MyIncomeController extends \yii\web\Controller
{
......@@ -9,7 +12,8 @@ class MyIncomeController extends \yii\web\Controller
public function actionIndex()
{
return $this->render('index');
$ret = Income::getIncomeListByUserId(Yii::$app->user->getId(), null);
return $this->render('index', $ret);
}
}
......@@ -3,6 +3,21 @@
$this->title = '知识有价';
?>
<div class="buy-recode-top">
<div class="col-md-4">
<h3>结算微信</h3>
<button class="btn btn-save">绑定</button>
</div>
<div class="col-md-4">
<h3>已结算</h3>
<p>¥162.03</p>
</div>
<div class="col-md-4">
<h3>待结算</h3>
<p>¥1829.00</p>
</div>
</div>
<div class="con-md-12">
<div class="table-responsive table-box">
<table class="table table-hover">
......@@ -16,16 +31,18 @@ $this->title = '知识有价';
</tr>
</thead>
<tbody>
<?php foreach ($data as $row) { ?>
<tr>
<td>
20012313131<br/>
2016-12-11
</td>
<td>18788860327 / 百丐洪七公</td>
<td><?=$row['order']['user']['']?> / 百丐洪七公</td>
<td>《中国为什么这么久还没有进入社会主义社会》</td>
<td>¥123.00</td>
<td>审核中</td>
</tr>
<?php } ?>
<tr>
<td>
20012313131<br/>
......@@ -39,16 +56,8 @@ $this->title = '知识有价';
</tbody>
</table>
<div class="text-center hide">
<ul class="pagination pagination-sm">
<li><a href="#">&laquo;</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">&raquo;</a></li>
</ul>
<div class="text-center">
<?=\yii\widgets\LinkPager::widget(['pagination'=>$pagination])?>
</div>
</div>
</div>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment