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

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

parent 693d0b1e
......@@ -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();
}
}
......@@ -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');
......
......@@ -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'));
}
}
......@@ -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>
......
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