Commit 50d71546 authored by 杨培's avatar 杨培

已售课程订单显示已结算/未结算的资金

parent 693d0b1e
...@@ -85,10 +85,19 @@ class Income extends \yii\db\ActiveRecord ...@@ -85,10 +85,19 @@ class Income extends \yii\db\ActiveRecord
// ->select('id,username,role,avatar'); // ->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]; $where = ['user_id'=>$userId];
$status != null && $where['status'] = $status; $status !== null && $where['status'] = $status;
$count = self::find()->where($where)->count(); $count = self::find()->where($where)->count();
$return = ['count'=>$count, 'data' =>[]]; $return = ['count'=>$count, 'data' =>[]];
...@@ -108,4 +117,21 @@ class Income extends \yii\db\ActiveRecord ...@@ -108,4 +117,21 @@ class Income extends \yii\db\ActiveRecord
return $return; 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();
}
} }
...@@ -120,16 +120,28 @@ class Orders extends \yii\db\ActiveRecord ...@@ -120,16 +120,28 @@ class Orders extends \yii\db\ActiveRecord
])->one(); ])->one();
} }
/**
* 关联下单用户信息
* @return $this
*/
public function getUser() public function getUser()
{ {
return $this->hasOne(User::className(), ['id'=>'user_id'])->select('id,username,telephone,role,avatar'); return $this->hasOne(User::className(), ['id'=>'user_id'])->select('id,username,telephone,role,avatar');
} }
/**
* 关联课程信息
* @return $this
*/
public function getCourse() public function getCourse()
{ {
return $this->hasOne(Course::className(), ['id'=>'course_id'])->select('id,user_id,name,price,preview_pic'); return $this->hasOne(Course::className(), ['id'=>'course_id'])->select('id,user_id,name,price,preview_pic');
} }
/**
* 关联课程信息(包括课程的讲师列表)
* @return $this
*/
public function getCourseWithTeachers() public function getCourseWithTeachers()
{ {
return $this->hasOne(Course::className(), ['id'=>'course_id'])->select('id,user_id,name,price,preview_pic')->with('teachers'); return $this->hasOne(Course::className(), ['id'=>'course_id'])->select('id,user_id,name,price,preview_pic')->with('teachers');
......
...@@ -16,8 +16,13 @@ class MyIncomeController extends \yii\web\Controller ...@@ -16,8 +16,13 @@ class MyIncomeController extends \yii\web\Controller
*/ */
public function actionIndex() public function actionIndex()
{ {
$ret = Income::getIncomeListByUserId(Yii::$app->user->getId(), null, 20); $uid = Yii::$app->user->getId();
return $this->render('index', $ret); $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'));
} }
} }
...@@ -10,11 +10,11 @@ $this->title = '知识有价'; ...@@ -10,11 +10,11 @@ $this->title = '知识有价';
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<h3>已结算</h3> <h3>已结算</h3>
<p>¥162.03</p> <p>¥<?=$settled?></p>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<h3>待结算</h3> <h3>待结算</h3>
<p>¥1829.00</p> <p>¥<?=$notSettled?></p>
</div> </div>
</div> </div>
......
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