GoodController.class.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Api\Controller;
  3. use Common\Controller\ApiController;
  4. class GoodController extends ApiController {
  5. public function __construct(){
  6. parent::__construct();
  7. }
  8. //获取精品课程
  9. public function index(){
  10. $isPopUp = I('is_popup','');
  11. $field = 'c.course_intro as 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';
  12. $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';
  13. $showTag = M('GoodCourseShow')->field('good_show as is_show')->find();
  14. $data = array('code'=>0,'msg'=>'','data'=>array());
  15. $data['pop_up'] = $this->showPop();
  16. $data['show_tag'] = isset($showTag['is_show'])?$showTag['is_show']:'0';
  17. if ($data['show_tag']){
  18. $res = M('GoodCourse')->join($join)->field($field)->order(array('good_sort'=>'asc','good_id'=>'desc'))->select();
  19. if ($res!=NULL){
  20. $userWordsRes = $this->square();
  21. foreach ($res as $key=>$row){
  22. if (in_array($row['course_id'], $userWordsRes) || $row['user_id']==$this->userId){
  23. $res[$key]['is_add'] = 1;
  24. }else{
  25. $res[$key]['is_add'] = 0;
  26. }
  27. }
  28. }
  29. if ($data['pop_up']){
  30. $data['data'] = $res;
  31. }else{
  32. if (empty($isPopUp)){
  33. $data['data'] = $res;
  34. }else {
  35. $data['data'] = array();
  36. }
  37. }
  38. }else{
  39. $data['data'] = array();
  40. }
  41. $this->returnData($data);exit;
  42. }
  43. //是否展示精品课程标签
  44. public function showTag(){
  45. $res = M('GoodCourseShow')->field('good_show as show_tag')->find();
  46. //$res['pop_up'] = $this->showPop();
  47. $data = array('code'=>0,'msg'=>'','data'=>$res);
  48. $this->returnData($data);exit;
  49. }
  50. //是否弹窗
  51. private function showPop(){
  52. $resShow = M('GoodCourseShow')->field('good_show')->find();
  53. if ($resShow['good_show']==0){
  54. return 0;
  55. }
  56. $ym = strtotime(date('Y-m'));
  57. $res = M('UserPop')->where(array('user_id'=>$this->userId,'operate_dt'=>$ym))->find();
  58. $isShow = 1;
  59. if ($res==NULL){
  60. M('UserPop')->add(array('user_id'=>$this->userId,'operate_dt'=>$ym));
  61. }else if($res['pop_num']<=6){
  62. M('UserPop')->where(array('pop_id'=>$res['pop_id']))->setInc('pop_num');
  63. }else{
  64. $isShow = 0;
  65. M('UserPop')->where(array('pop_id'=>$res['pop_id']))->setInc('pop_num');
  66. }
  67. return $isShow;
  68. }
  69. //获取已经添加的课程或者自由记
  70. private function square($uwType=0){
  71. $condition = array('user_id'=>$this->userId,'is_show'=>1);
  72. if (!empty($uwType)){
  73. $condition['uw_type'] = $uwType;
  74. }
  75. $res = M('UserWords')->where($condition)->field('course_id')->select();
  76. if ($res==NULL){
  77. return array();
  78. }
  79. $arr = array();
  80. foreach ($res as $r){
  81. $arr[] = $r['course_id'];
  82. }
  83. return $arr;
  84. }
  85. }