123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace Api\Controller;
- use Common\Controller\ApiController;
- class GoodController extends ApiController {
- public function __construct(){
- parent::__construct();
- }
-
- //获取精品课程
- public function index(){
- $isPopUp = I('is_popup','');
- $field = 'gc.course_info,gc.operate_dt,c.course_id,c.course_name,c.course_num,c.course_join,c.user_id as uid,u.user_name,u.user_id,u.user_icon';
- $join = 'gc LEFT JOIN t_course c ON gc.course_id=c.course_id LEFT JOIN t_user u ON c.user_id=u.user_id';
-
- $showTag = M('GoodCourseShow')->field('good_show as is_show')->find();
- $data = array('code'=>0,'msg'=>'','data'=>array());
- $data['pop_up'] = $this->showPop();
- $data['show_tag'] = isset($showTag['is_show'])?$showTag['is_show']:'0';
- if ($data['show_tag']){
- $res = M('GoodCourse')->join($join)->field($field)->order(array('good_sort'=>'asc','good_id'=>'desc'))->select();
- if ($res!=NULL){
- $userWordsRes = $this->square();
- foreach ($res as $key=>$row){
- if (in_array($row['course_id'], $userWordsRes) || $row['user_id']==$this->userId){
- $res[$key]['is_add'] = 1;
- }else{
- $res[$key]['is_add'] = 0;
- }
- }
- }
- if ($data['pop_up']){
- $data['data'] = $res;
- }else{
- if (empty($isPopUp)){
- $data['data'] = $res;
- }else {
- $data['data'] = array();
- }
- }
- }else{
- $data['data'] = array();
- }
- $this->returnData($data);exit;
- }
-
- //是否展示精品课程标签
- public function showTag(){
- $res = M('GoodCourseShow')->field('good_show as show_tag')->find();
- //$res['pop_up'] = $this->showPop();
- $data = array('code'=>0,'msg'=>'','data'=>$res);
- $this->returnData($data);exit;
- }
-
- //是否弹窗
- private function showPop(){
- $resShow = M('GoodCourseShow')->field('good_show')->find();
- if ($resShow['good_show']==0){
- return 0;
- }
- $ym = strtotime(date('Y-m'));
- $res = M('UserPop')->where(array('user_id'=>$this->userId,'operate_dt'=>$ym))->find();
- $isShow = 1;
- if ($res==NULL){
- M('UserPop')->add(array('user_id'=>$this->userId,'operate_dt'=>$ym));
- }else if($res['pop_num']<=6){
- M('UserPop')->where(array('pop_id'=>$res['pop_id']))->setInc('pop_num');
- }else{
- $isShow = 0;
- M('UserPop')->where(array('pop_id'=>$res['pop_id']))->setInc('pop_num');
- }
- return $isShow;
- }
-
- //获取已经添加的课程或者自由记
- private function square($uwType=0){
- $condition = array('user_id'=>$this->userId,'is_show'=>1);
- if (!empty($uwType)){
- $condition['uw_type'] = $uwType;
- }
- $res = M('UserWords')->where($condition)->field('course_id')->select();
- if ($res==NULL){
- return array();
- }
- $arr = array();
- foreach ($res as $r){
- $arr[] = $r['course_id'];
- }
- return $arr;
- }
- }
|