$this->mall_id], ['=', 'status', StatusEnum::ENABLED], ['is_show' => CourseEnum::IS_SHOW]]; $params['order'] = 'sort desc,created_at desc'; $params['select'] = 'id,sort,title,pic_link as link,pic_path'; $banner = AddonsCourseBanners::lists($params); $cate = CourseCategory::lists(['select' => 'id,sort,cname as cate_name,logo', 'where' => [['mall_id' => $this->mall_id], ['=', 'status', StatusEnum::ENABLED], ['is_navicat' => CourseEnum::IS_NAVICAT]], 'order' => 'sort asc,created_at desc']); $group = AddonsCourseGroups::lists(['select' => 'id,cid as course_id,sort,gname as group_name,logo', 'where' => [['mall_id' => $this->mall_id], ['=', 'status', StatusEnum::ENABLED]], 'order' => 'sort asc,created_at desc']); $activity = AddonsCourseActivity::lists([ 'select' => 'id,name,logo,goods_id', 'where' => [ ['mall_id' => $this->mall_id], ['=', 'status', StatusEnum::ENABLED] ], 'order' => 'id desc', 'limit' => 3 ]); if ($activity) { $activity = CourseActivityService::getList($activity, $this->mall_id); } if ($banner) { foreach ($banner as $k => &$v) { if (!empty($v['link'])) { $v['link'] = json_decode($v['link']); } } } if ($group) { foreach ($group as $item => &$val) { if (empty($val['course_id'])) { $val['course_info'][] = []; } else { $course_ids = \Qiniu\json_decode($val['course_id']); $is_bought_list = AddonsCourseBought::checkIsBought($course_ids, $this->user_id); $course_info = AddonsCourse::getCourseListWithMemberprice($this->user, $this->mall_id, $course_ids, [], 'sell_type,allow_member_levels', 8); if ($course_info['list']) { foreach ($course_info['list'] as $k => &$v) { $v['is_bought'] = 0; if (isset($is_bought_list[$v['id']])) { $v['is_bought'] = 1; } } } $val['course_info'] = $course_info['list']; } } } $index_title = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_COURSE, 'basic.index_title'); $is_promoter = 0; if(!empty($this->user_id)){ $res = CoursePromoter::findOne(['user_id'=>$this->user_id,'mall_id'=>$this->mall_id,'status'=>StatusEnum::ENABLED]); if(!empty($res)) $is_promoter= 1; } return $this->success('操作成功', compact('banner', 'group', 'cate', 'index_title','is_promoter', 'activity')); } /** * @name: actionAllCourseInCategory * @msg: 获取某一个分类下的所有课程 * @param integer $id 课程分类id * @return {*} */ public function actionAllCourseInCategory() { $get = \Yii::$app->request->get(); $res = \Yii::$app->services->validate->validate($get, [ [['cate_id'], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); if ($get['cate_id'] == 0) { $cateWhere = []; } else { $cateWhere = ['cat_id' => $get['cate_id']]; } $list = AddonsCourse::getCourseListWithMemberPrice($this->user, $this->mall_id, null, $cateWhere, 'sell_type,allow_member_levels'); if($list['list']){ $course_ids = array_column($list['list'],'id'); $is_bought_list = AddonsCourseBought::checkIsBought($course_ids, $this->user_id); foreach ($list['list'] as $k => &$v) { $v['is_bought'] = 0; if (isset($is_bought_list[$v['id']])) { $v['is_bought'] = 1; } $v['views'] += $v['vm_views']; } } return $this->success('获取数据成功', $list); } /** * @name: actionAllCourseInCategory * @msg: 获取某一个分组下的所有的课程 * @param integer $id 课程分组 id * @return {*} */ public function actionAllCourseInGroup() { $get = \Yii::$app->request->get(); $res = \Yii::$app->services->validate->validate($get, [ [['group_id'], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $course_info = AddonsCourseGroups::getOne([['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $get['group_id']]]); $course_ids = \Qiniu\json_decode($course_info->cid); $list = AddonsCourse::getCourseListWithMemberprice($this->user, $this->mall_id, $course_ids, [], 'sell_type,allow_member_levels'); if($list['list']){ $is_bought_list = AddonsCourseBought::checkIsBought($course_ids, $this->user_id); foreach ($list['list'] as $k => &$v) { $v['is_bought'] = 0; if (isset($is_bought_list[$v['id']])) { $v['is_bought'] = 1; } $v['views'] += $v['vm_views']; } } return $this->success('获取数据成功', $list); } /** * @name: * @msg: 课程搜索 * @param {string} $key_word 搜索关键字 * @return {*} */ public function actionSearch() { $get = \Yii::$app->request->get(); $res = \Yii::$app->services->validate->validate($get, [ [['key_word'], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $andWhere = ['or', ['like', 'name', $get['key_word']], ['like', 'introduce', $get['key_word']]]; $list = AddonsCourse::getCourseListWithMemberprice($this->user, $this->mall_id, null, $andWhere, 'sell_type,allow_member_levels'); if($list['list']){ $course_ids = array_column($list['list'],'id'); $is_bought_list = AddonsCourseBought::checkIsBought($course_ids, $this->user_id); foreach ($list['list'] as $k => &$v) { $v['is_bought'] = 0; if (isset($is_bought_list[$v['id']])) { $v['is_bought'] = 1; } } } return $this->success('获取数据成功', $list); } public function actionGetConfig() { $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_COURSE, 'basic'); return $this->success('success', $settings); } public function actionMyDirectUser(){ try { $params = \Yii::$app->request->get(); $res = CoursePromoter::findOne(['user_id'=>$this->user_id,'mall_id'=>$this->mall_id,'status'=>StatusEnum::ENABLED]); if(empty($res)) return $this->error('您不是推广员'); $where = []; $where[] = ['mall_id'=>$this->mall_id]; $where[] = ['parent_id'=>$this->user_id]; $where[] = ['status'=> [StatusEnum::ENABLED, StatusEnum::DISABLED]]; $user_list = User::lists(['where'=>$where,'index'=>'id','select'=>'id,avatar_url,mobile,nickname']); $user_ids = array_column($user_list,'id'); $params['where'][] = ['mall_id'=>$this->mall_id]; $params['where'][] = ['user_id'=>$user_ids]; $params['where'][] = ['status'=> [StatusEnum::ENABLED, StatusEnum::DISABLED]]; $order = 'duration desc'; if(!empty($params['order_type'])){ if($params['order_type']==2){ $order = 'register_time desc'; } } $params['order'] = $order; $params['select'] = 'id,mall_id,user_id,register_time,duration'; $list = CourseUserWatch::listPage($params); if(!empty($list['list'])){ foreach ($list['list'] as &$item){ $item['avatar_url'] = $item['nickname']=$item['mobile']=''; if(isset($user_list[$item['user_id']])){ $item['avatar_url'] = $user_list[$item['user_id']]['avatar_url']; $item['mobile'] = $user_list[$item['user_id']]['mobile']; $item['nickname'] = $user_list[$item['user_id']]['nickname']; } $item['text'] = Watch::getText($item['duration']); } } return $this->success('成功', $list); }catch (\Exception $e){ return $this->error($e->getMessage()); } } public function actionMyDirectUserIntention(){ try { $params = \Yii::$app->request->get(); $res = CoursePromoter::findOne(['user_id'=>$this->user_id,'mall_id'=>$this->mall_id,'status'=>StatusEnum::ENABLED]); if(empty($res)) return $this->error('您不是推广员'); $user_id = $params['user_id']; $list = CourseWatchLog::lists(['where'=>[['user_id'=>$user_id]]]); $course_ids = array_column($list,'course_id'); $watch_duration = array_sum(array_column($list,'duration')); $course_chapter_list = AddonsCourseChapter::lists(['where'=>[['course_id'=>$course_ids]]]); $total_duration = 0; foreach ($course_chapter_list as $item){ if(!empty($item['video_length'])){ $video_length_arr = explode(':',$item['video_length']); if(count($video_length_arr)>1){ $duration = $video_length_arr[0]*3600+$video_length_arr[1]*60+ bcadd($video_length_arr[2],0,0); }else{ $duration =$video_length_arr[0]; } $total_duration+=$duration; } } $intention = '一般意向'; if(!empty($total_duration)&&!empty($watch_duration)){ $schedule = bcmul($watch_duration/$total_duration,100,2); if($schedule>70){ $intention='高意向'; }elseif ($schedule>30){ $intention='中意向'; } } return $this->success('成功', ['intention'=>$intention,'watch_duration'=>$watch_duration,'total_duration'=>$total_duration]); }catch (\Exception $e){ return $this->error($e->getMessage()); } } public function actionGetSetting() { try { $config = \Yii::$app->services->setting->addons->get($this->mall_id, CourseEnum::ADDONS_NAME, 'basic'); if (empty($config['style'])) $config['style'] = 1; return $this->success('获取成功', $config); } catch (\Exception $e) { return $this->error($e->getMessage()); } } }