Commit 5691360f authored by xiabin's avatar xiabin

添加注释

parent 9a29fa00
......@@ -187,6 +187,6 @@ class Course extends \yii\db\ActiveRecord
*/
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
return $this->hasOne(User::className(), ['id' => 'user_id'])->select('id,username,role,avatar');;
}
}
......@@ -109,6 +109,6 @@ class Favorite extends \yii\db\ActiveRecord
*/
public function getCourse()
{
return $this->hasOne(Course::className(), ['id' => 'course_id'])->with('teachers')->with('user');
return $this->hasOne(Course::className(), ['id' => 'course_id'])->with('teachers')->with('user')->select('id,user_id,name,price,preview_pic');
}
}
......@@ -74,17 +74,21 @@ class Income extends \yii\db\ActiveRecord
];
}
/**
* @return $this
*/
public function getOrder()
{
return $this->hasOne(Orders::className(), ['id'=>'orders_id'])->with('user')->with('courseWithTeachers');
}
//public function getUser()
//{
// return $this->hasOne(User::className(), ['id'=>'user_id'])->viaTable(Orders::tableName(), ['id'=>'orders_id'])
// ->select('id,username,role,avatar');
//}
/**
* @param $userId
* @param int $page
* @param int $num
* @param int $status
* @return array
*/
public static function getIncomeListByUserId($userId, $page=0, $num=10, $status=self::STATUS_NOT_SETTLED)
{
$where = ['user_id'=>$userId];
......
......@@ -98,8 +98,8 @@ class Orders extends \yii\db\ActiveRecord
//获取总数
$count = self::find()->where($condition, $params)->count();
$start = $page * $num;
$data = self::find()->select("$tableA.course_id,$tableA.created_at as purchased_time,$tableB.name,$tableB.price,$tableB.free_time,$tableB.intro,$tableB.preview_pic,$tableB.created_at")
->where($condition, $params)->limit($num)->offset($start)->orderBy("$tableA.created_at DESC")->join('left join ', $tableB, "$tableA.course_id = $tableB.id")->asArray()->all();
$data = self::find()
->where($condition, $params)->limit($num)->offset($start)->orderBy("$tableA.created_at DESC")->joinWith('courseWithTeachers')->asArray()->all();
return [
'count' => $count,
'data' => $data
......@@ -119,17 +119,26 @@ 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');
......
......@@ -79,7 +79,7 @@ class UserCenterController extends Controller
$page = Yii::$app->request->get('page', 0);
$num = Yii::$app->request->get('num', 10);
$purchasedCourse = Orders::findPurchasedCourseByUserId(Yii::$app->user->getId(), $page, $num);
var_dump($purchasedCourse);
var_dump($purchasedCourse);exit;
return $this->render('purchasedCourse');
}
......@@ -94,7 +94,6 @@ class UserCenterController extends Controller
$page--;
$num = Yii::$app->request->get('per-page', 10);
$favorite = Favorite::findByUserId(Yii::$app->user->getId(), $page, $num);
// var_dump($favorite);exit;
return $this->render('favorite', [
'favorite' => $favorite
]);
......@@ -107,6 +106,7 @@ class UserCenterController extends Controller
public function actionBrowseRecord()
{
$browseRecord = BrowseRecord::getByUserId(Yii::$app->user->getId());
return $this->render('browseRecord');
}
......
......@@ -32,7 +32,7 @@ $this->beginContent('@app/views/layouts/center.php');
<li <?= (Yii::$app->controller->id === 'user-center' and Yii::$app->controller->action->id === 'browse-record') ? 'class = "active"' : '' ?>>
<a href="<?= $baseUrl . '/user-center/browse-record' ?>"><i class="glyphicon glyphicon-eye-open"></i>浏览记录</a>
</li>
<li><a href="javascript:;"><i class="glyphicon glyphicon-play-circle"></i>我的课堂</a></li>
<li><a href="<?=$baseUrl .'/my-course'?>"><i class="glyphicon glyphicon-play-circle"></i>我的课堂</a></li>
<li><a href="<?=$baseUrl .'/site/logout'?>"><i class="glyphicon glyphicon-off"></i>退出登录</a></li>
</ul>
......
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