CourseController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace backend\controllers;
  3. use common\components\util;
  4. use common\services\xhTrainStudentService;
  5. use common\models\xhTrainUserCourse;
  6. use common\models\xhTrainStudent;
  7. use Yii;
  8. use yii\web\Controller;
  9. use yii\filters\AccessControl;
  10. use yii\data\Pagination;
  11. use common\models\xhTrainCourse;
  12. use common\services\xhUserService;
  13. class CourseController extends BackendController
  14. {
  15. public function actionList()
  16. {
  17. $query = xhTrainUserCourse::find();
  18. $merchantId = $this->merchantId;
  19. $query->where(['merchantId' =>$merchantId,'status' => 1]);
  20. $query->orderBy('attendTime desc');
  21. $countQuery = clone $query;
  22. $pages = new Pagination(['totalCount' => $countQuery->count(),'pageSize' => 50]);
  23. $models = $query->offset($pages->offset)->limit($pages->limit)->with('xhUser')->asArray()->all();
  24. $weekReturn = Yii::$app->redis->executeCommand('ZREVRANGE', ["merchant{$this->merchantId}UserWeek".date("Y-W")."PraiseNum", 0,10, 'WITHSCORES']);
  25. $weekRank = [];
  26. if(!empty($weekReturn)){
  27. $i = 0;
  28. $x = 0;
  29. foreach($weekReturn as $key => $val){
  30. $i++;
  31. if($i%2 == 0){
  32. $weekRank[$x]['praiseNum'] = $val;
  33. $x++;
  34. }else{
  35. $userInfo = xhUserService::getById($val);
  36. unset($userInfo['payPassword']);
  37. unset($userInfo['password']);
  38. $weekRank[$x]['userInfo'] = $userInfo;
  39. $weekRank[$x]['userId'] = $val;
  40. }
  41. }
  42. }
  43. $monthReturn = Yii::$app->redis->executeCommand('ZREVRANGE', ["merchant{$this->merchantId}UserMonth".date("Y-m")."PraiseNum", 0,10, 'WITHSCORES']);
  44. $monthRank = [];
  45. if(!empty($monthReturn)){
  46. $i = 0;
  47. $x = 0;
  48. foreach($monthReturn as $key => $val){
  49. $i++;
  50. if($i%2 == 0){
  51. $monthRank[$x]['praiseNum'] = $val;
  52. $x++;
  53. }else{
  54. $userInfo = xhUserService::getById($val);
  55. unset($userInfo['payPassword']);
  56. unset($userInfo['password']);
  57. $monthRank[$x]['userInfo'] = $userInfo;
  58. $monthRank[$x]['userId'] = $val;
  59. }
  60. }
  61. }
  62. return $this->render('list', ['models' => $models,'pages' => $pages,'monthRank' => $monthRank,'weekRank' => $weekRank]);
  63. }
  64. public function actionDetail()
  65. {
  66. $get = Yii::$app->request->get();
  67. $id = isset($get['id']) ? $get['id'] : 0;
  68. $student = xhTrainStudent::getByCondition(['id' => $id]);
  69. if(empty($student)){
  70. util::stop('没有获取到学员信息哦~');
  71. }
  72. $course = xhTrainUserCourse::getAllByCondition(['studentId' => $id]);
  73. return $this->render('detail',['course' => $course]);
  74. }
  75. }