Course.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace Content\V1;
  3. use Dever;
  4. use Content\Lib\Base;
  5. class Course extends Base
  6. {
  7. /**
  8. * @api {get} v1/course.list 听课列表
  9. * @apiVersion 1.0.0
  10. * @apiName course.list
  11. * @apiGroup Data
  12. *
  13. * @apiDescription 小程序的听课列表接口
  14. *
  15. * @apiParam {Number} appid 小程序id
  16. *
  17. * @apiSuccess {Object[]} info 小程序基本信息
  18. * @apiSuccess {Number} info.id 小程序id
  19. * @apiSuccess {String} info.name 小程序名称
  20. * @apiSuccess {Number} info.cate_id 小程序所属栏目id
  21. * @apiSuccess {String} info.logo 小程序logo
  22. * @apiSuccess {String} info.title 首页标题
  23. * @apiSuccess {String} info.pic 首页头图
  24. *
  25. * @apiSuccess {Object[]} course 听课信息
  26. * @apiSuccess {Number} course.id 听课id
  27. * @apiSuccess {String} course.name 听课标题
  28. * @apiSuccess {String} course.content 听课内容
  29. * @apiSuccess {String} course.pic 听课封面
  30. * @apiSuccess {String} course.top 听课详情页头图
  31. * @apiSuccess {String} course.num_view 阅读数
  32. * @apiSuccess {String} course.num_watch 观看人数
  33. * @apiSuccess {String} course.num_review 评论数
  34. * @apiSuccess {String} course.num_up 赞数
  35. * @apiSuccess {String} course.video 视频地址
  36. * @apiSuccess {String} course.audio 音频地址
  37. * @apiSuccess {String} course.cdate 时间
  38. *
  39. * @apiSuccess {Object[]} course.author 作者信息
  40. * @apiSuccess {Number} course.author.id 作者id
  41. * @apiSuccess {String} course.author.name 作者姓名
  42. * @apiSuccess {String} course.author.pic 作者头像
  43. *
  44. * @apiSuccessExample 操作成功
  45. * {"status":1,"code":1,"msg":"success","data":{"info":{"id":"1","name":"\u7279\u8272\u5c0f\u9547\u600e\u4e48\u641e","cate_id":"1","logo":"http:\/\/192.168.33.10\/plant\/data\/upload\/1\/2018\/03\/24\/1e493a87d4cdddde7fd06ad9762694d2.jpg","title":"test","pic":"http:\/\/192.168.33.10\/plant\/data\/upload\/1\/2018\/03\/24\/da31b5d54d15192fea10406f77f4b0cb.jpg","state":"1","cdate":"1521858466"},"course":[{"id":"1","name":"\u662f\u662f\u662f","pic":["http:\/\/192.168.33.10\/plant\/data\/upload\/1\/2018\/03\/24\/da31b5d54d15192fea10406f77f4b0cb.jpg"],"top":"http:\/\/192.168.33.10\/plant\/data\/upload\/1\/2018\/03\/24\/da31b5d54d15192fea10406f77f4b0cb.jpg","info_id":"1","author_id":"1","content":"<p>23132323<\/p>","num_view":"2","cdate":"1\u5206\u949f\u524d","author":{"id":"1","name":"\u7a0b\u8302","pic":"http:\/\/192.168.33.10\/plant\/data\/upload\/1\/2018\/03\/24\/1e493a87d4cdddde7fd06ad9762694d2.jpg","state":"1","cdate":"1521858481"}}]},"page":{"total":"1","current_page":1,"total_page":1,"next_page":1,"prev_page":1,"html":"","status":0}}
  46. *
  47. * @apiErrorExample 操作失败
  48. * {"status":2,"code":1,"msg":"\u9519\u8bef\u7684\u5c0f\u7a0b\u5e8fid"}
  49. */
  50. public function list_api()
  51. {
  52. $this->data['course'] = Dever::load('content/course-getAll', array('option_info_id' => $this->data['info']['id']));
  53. if ($this->data['course']) {
  54. foreach ($this->data['course'] as $k => $v) {
  55. $this->data['course'][$k] = $this->one($v);
  56. }
  57. }
  58. return $this->data;
  59. }
  60. /**
  61. * @api {get} v1/course.view 课程详情
  62. * @apiVersion 1.0.0
  63. * @apiName course.view
  64. * @apiGroup Data
  65. *
  66. * @apiDescription 小程序的课程详情接口
  67. *
  68. * @apiParam {Number} appid 小程序id
  69. * @apiParam {Number} id 课程id
  70. *
  71. * @apiSuccess {Object[]} info 小程序基本信息
  72. * @apiSuccess {Number} info.id 小程序id
  73. * @apiSuccess {String} info.name 小程序名称
  74. * @apiSuccess {Number} info.cate_id 小程序所属栏目id
  75. * @apiSuccess {String} info.logo 小程序logo
  76. * @apiSuccess {String} info.title 首页标题
  77. * @apiSuccess {String} info.pic 首页头图
  78. *
  79. * @apiSuccess {Object[]} course 听课信息
  80. * @apiSuccess {Number} course.id 听课id
  81. * @apiSuccess {String} course.name 听课标题
  82. * @apiSuccess {String} course.content 听课内容
  83. * @apiSuccess {String} course.pic 听课封面
  84. * @apiSuccess {String} course.top 听课详情页头图
  85. * @apiSuccess {String} course.num_watch 观看人数
  86. * @apiSuccess {String} course.num_view 阅读数
  87. * @apiSuccess {String} course.num_review 评论数
  88. * @apiSuccess {String} course.num_up 赞数
  89. * @apiSuccess {String} course.video 视频地址
  90. * @apiSuccess {String} course.audio 音频地址
  91. * @apiSuccess {String} course.cdate 时间
  92. *
  93. * @apiSuccess {Object[]} course.author 作者信息
  94. * @apiSuccess {Number} course.author.id 作者id
  95. * @apiSuccess {String} course.author.name 作者姓名
  96. * @apiSuccess {String} course.author.pic 作者头像
  97. *
  98. * @apiSuccess {Object[]} course.user 观看用户信息
  99. * @apiSuccess {Number} course.user.id 用户id
  100. * @apiSuccess {String} course.user.name 用户姓名
  101. * @apiSuccess {String} course.user.pic 用户头像
  102. *
  103. * @apiSuccessExample 操作成功
  104. * {"status":1,"code":1,"msg":"success","data":{"info":{"id":"1","name":"\u7279\u8272\u5c0f\u9547\u600e\u4e48\u641e","cate_id":"1","logo":"http:\/\/192.168.33.10\/plant\/data\/upload\/1\/2018\/03\/24\/1e493a87d4cdddde7fd06ad9762694d2.jpg","title":"test","pic":"http:\/\/192.168.33.10\/plant\/data\/upload\/1\/2018\/03\/24\/da31b5d54d15192fea10406f77f4b0cb.jpg","state":"1","cdate":"1521858466"},"course":{"id":"1","name":"\u662f\u662f\u662f","info_id":"1","author_id":"1","video":"123123","audio":"3232","num_add_view":"0","num_up":"0","num_view":"1","num_review":"0","pic":["http:\/\/192.168.33.10\/plant\/data\/upload\/1\/2018\/03\/24\/da31b5d54d15192fea10406f77f4b0cb.jpg"],"top":"http:\/\/192.168.33.10\/plant\/data\/upload\/1\/2018\/03\/24\/da31b5d54d15192fea10406f77f4b0cb.jpg","content":"<p>23132323<\/p>","reorder":"1","state":"1","cdate":"42\u79d2\u524d","author":{"id":"1","name":"\u7a0b\u8302","pic":"http:\/\/192.168.33.10\/plant\/data\/upload\/1\/2018\/03\/24\/1e493a87d4cdddde7fd06ad9762694d2.jpg","state":"1","cdate":"1521858481"}}}}
  105. *
  106. * @apiErrorExample 操作失败
  107. * {"status":2,"code":1,"msg":"\u9519\u8bef\u7684\u5c0f\u7a0b\u5e8fid"}
  108. */
  109. public function view_api()
  110. {
  111. $id = Dever::input('id');
  112. if ($id > 0) {
  113. $course = Dever::load('content/course-one', $id);
  114. if ($course) {
  115. $this->data['course'] = $this->one($course);
  116. $watch = Dever::load('comment/watch-state', array('option_info_id' => $this->data['info']['id'], 'option_course_id' => $id));
  117. $this->data['course']['user'] = array();
  118. if ($watch) {
  119. foreach($watch as $k => $v) {
  120. $this->data['course']['user'][] = Dever::load('passport/user-one', $v['uid']);
  121. }
  122. }
  123. $this->data['course']['user_count'] = count($this->data['course']['user']);
  124. # 增加阅读量
  125. Dever::load('content/course-addView', $id);
  126. } else {
  127. Dever::alert('错误的课程id');
  128. }
  129. } else {
  130. Dever::alert('错误的课程id');
  131. }
  132. $this->data['vote'] = $this->vote(2, $id);
  133. return $this->data;
  134. }
  135. }