CourseAction.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. /**
  3. *
  4. */
  5. class CourseAction extends CommonAction
  6. {
  7. public function index()
  8. {
  9. $map = array('type' => 0);
  10. $id = intval($_REQUEST['id']);
  11. $title = trim($_REQUEST['title']);
  12. if ($id) {
  13. $map['id'] = $id;
  14. }
  15. if ($title) {
  16. $map['title'] = array('like', '%' . trim($title) . '%');
  17. }
  18. $model = D('Course');
  19. if (!empty($model)) {
  20. $this->_list($model, $map);
  21. }
  22. $this->display();
  23. }
  24. public function set_effect()
  25. {
  26. $id = intval($_REQUEST['id']);
  27. $ajax = intval($_REQUEST['ajax']);
  28. $info = M('Course')->where("id=" . $id)->getField("title");
  29. $c_is_effect = M('Course')->where("id=" . $id)->getField("is_effect"); //当前状态
  30. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  31. M('Course')->where("id=" . $id)->setField("is_effect", $n_is_effect);
  32. save_log($info . l("SET_EFFECT_" . $n_is_effect), 1);
  33. clear_auto_cache("get_help_cache");
  34. clear_auto_cache("article_notice");
  35. $this->ajaxReturn($n_is_effect, l("SET_EFFECT_" . $n_is_effect), 1);
  36. }
  37. public function set_recommend()
  38. {
  39. $id = intval($_REQUEST['id']);
  40. $ajax = intval($_REQUEST['ajax']);
  41. $info = M('Course')->where("id=" . $id)->getField("title");
  42. $c_is_recommend = M('Course')->where("id=" . $id)->getField("is_recommend"); //当前状态
  43. $n_is_recommend = $c_is_recommend == 0 ? 1 : 0; //需设置的状态
  44. M('Course')->where("id=" . $id)->setField("is_recommend", $n_is_recommend);
  45. save_log($info . l("SET_EFFECT_" . $n_is_recommend), 1);
  46. clear_auto_cache("get_help_cache");
  47. clear_auto_cache("article_notice");
  48. $this->ajaxReturn($n_is_recommend, l("SET_EFFECT_" . $n_is_recommend), 1);
  49. }
  50. public function edit()
  51. {
  52. $id = intval($_REQUEST['id']);
  53. $vo = M('Course')->find($id);
  54. $this->assign('vo', $vo);
  55. $this->display();
  56. }
  57. public function update()
  58. {
  59. $data = M('Course')->create();
  60. $data['img'] = $_REQUEST['image'];
  61. //clear_auto_cache("prop_list");
  62. $log_info = M('Course')->where("id=" . intval($data['id']))->getField("title");
  63. //开始验证有效性
  64. $this->assign("jumpUrl", u('Course' . "/edit", array("id" => $data['id'])));
  65. if (!check_empty($data['title'])) {
  66. $this->error("请输入课程名称");
  67. }
  68. if (!check_empty($data['img'])) {
  69. $this->error("请上传封面");
  70. }
  71. if (!check_empty($data['content'])) {
  72. $this->error("请输入内容");
  73. }
  74. $data['type'] = 0;
  75. // 更新数据
  76. if ($data['id']) {
  77. $list = M('Course')->save($data);
  78. } else {
  79. $data['create_time'] = NOW_TIME;
  80. $list = M('Course')->add($data);
  81. }
  82. if (false !== $list) {
  83. //成功提示
  84. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  85. clear_auto_cache("prop_id", array('id' => $data['id']));
  86. $this->success(L("UPDATE_SUCCESS"));
  87. } else {
  88. //错误提示
  89. save_log($log_info . L("UPDATE_FAILED"), 0);
  90. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  91. }
  92. }
  93. public function view()
  94. {
  95. $id = intval($_REQUEST['id']);
  96. $sid = intval($_REQUEST['sid']);
  97. $title = trim($_REQUEST['title']);
  98. $sort = $_REQUEST['_sort'] ? 'asc' : 'desc';
  99. if (isset($_REQUEST['_order'])) {
  100. $order = $_REQUEST['_order'];
  101. } else {
  102. $order = 'id';
  103. }
  104. $model = M('CourseSeason');
  105. $map = array('pid' => $id);
  106. if ($sid) {
  107. $map['id'] = $sid;
  108. }
  109. if ($title) {
  110. $map['title'] = array('like', '%' . trim($title) . '%');
  111. }
  112. $count = $model->where($map)->count('id');
  113. if ($count > 0) {
  114. //创建分页对象
  115. if (!empty($_REQUEST['listRows'])) {
  116. $listRows = $_REQUEST['listRows'];
  117. } else {
  118. $listRows = '';
  119. }
  120. $p = new Page($count, $listRows);
  121. //分页查询数据
  122. $voList = $model->where($map)->order("season")->limit($p->firstRow . ',' . $p->listRows)->findAll();
  123. foreach ($map as $key => $val) {
  124. if (!is_array($val)) {
  125. $p->parameter .= "$key=" . urlencode($val) . "&";
  126. }
  127. }
  128. //分页显示
  129. $page = $p->show();
  130. //列表排序显示
  131. $sortImg = $sort; //排序图标
  132. $sortAlt = $sort == 'desc' ? l("ASC_SORT") : l("DESC_SORT"); //排序提示
  133. $sort = $sort == 'desc' ? 1 : 0; //排序方式
  134. //模板赋值显示
  135. foreach ($voList as $k => $v) {
  136. $voList[$k]['head_image'] = get_spec_image($v['head_image']);
  137. }
  138. $this->assign('list', $voList);
  139. $this->assign('sort', $sort);
  140. $this->assign('order', $order);
  141. $this->assign('sortImg', $sortImg);
  142. $this->assign('sortType', $sortAlt);
  143. $this->assign("page", $page);
  144. $this->assign("nowPage", $p->nowPage);
  145. }
  146. $this->assign('id', $id);
  147. $this->display();
  148. }
  149. public function viewSeason()
  150. {
  151. $id = intval($_REQUEST['id']);
  152. $pid = intval($_REQUEST['pid']);
  153. $vo = M('CourseSeason')->find($id);
  154. if ($vo) {
  155. $pid = $vo['pid'];
  156. }
  157. $m_config = load_auto_cache("m_config");
  158. $qcloud_secret_id = $m_config['qcloud_secret_id'];
  159. $qcloud_secret_key = $m_config['qcloud_secret_key'];
  160. if ($vo['video_url'] && !intval($vo['video_url'])) {
  161. $video_url = $vo['video_url'];
  162. } else {
  163. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  164. $video_factory = new VideoFactory();
  165. $video = $video_factory->DescribeVodPlayUrls($vo['file_id']);
  166. $video_url = $video['urls'][min(array_keys($video['urls']))];
  167. }
  168. $this->assign('video_url', $video_url);
  169. $this->assign('pid', $pid);
  170. $this->assign('vo', $vo);
  171. $this->assign('qcloud_secret_id', $qcloud_secret_id);
  172. $this->assign('qcloud_secret_key', $qcloud_secret_key);
  173. $this->display();
  174. }
  175. public function updateSeason()
  176. {
  177. // $video_vid = $_REQUEST['file_id'];
  178. $data = M('CourseSeason')->create();
  179. $data['img'] = $_REQUEST['image'];
  180. //clear_auto_cache("prop_list");
  181. //开始验证有效性
  182. $this->assign("jumpUrl", u('Course' . "/viewSeason", array("id" => $data['id'])));
  183. if (!check_empty($data['title'])) {
  184. ajax_return(array('status' => 0, 'error' => '请输入课程名称'));
  185. }
  186. if (!check_empty($data['img'])) {
  187. ajax_return(array('status' => 0, 'error' => '请上传封面'));
  188. }
  189. if (!check_empty($data['content'])) {
  190. ajax_return(array('status' => 0, 'error' => '请输入内容'));
  191. }
  192. // $data['video_url'] = $video_vid;
  193. // 更新数据
  194. if ($data['id']) {
  195. $res = M('CourseSeason')->save($data);
  196. } else {
  197. $data['create_time'] = NOW_TIME;
  198. $res = M('CourseSeason')->add($data);
  199. }
  200. if (false !== $res) {
  201. ajax_return(array('status' => 1, 'error' => '更新成功'));
  202. } else {
  203. ajax_return(array('status' => 0, 'error' => '更新错误'));
  204. }
  205. }
  206. public function upload()
  207. {
  208. $result = $this->uploadFile();
  209. if ($result['status'] == 1) {
  210. ajax_return(array(
  211. 'status' => $result['status'],
  212. 'success' => $result['info'],
  213. 'url' => get_domain() . $result['data'][0]['recpath'] . $result['data'][0]['savename'],
  214. 'result' => $result,
  215. ));
  216. } else {
  217. ajax_return(array(
  218. 'status' => $result['status'],
  219. 'error' => $result['info'],
  220. ));
  221. }
  222. }
  223. public function getVideoUrlById()
  224. {
  225. $id = trim($_REQUEST['id']);
  226. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  227. $video_factory = new VideoFactory();
  228. $video = $video_factory->DescribeVodPlayUrls($id);
  229. $video_url = $video['urls'][min(array_keys($video['urls']))];
  230. if ($video_url) {
  231. ajax_return(array(
  232. 'status' => 1,
  233. 'error' => '',
  234. 'url' => $video_url,
  235. ));
  236. } else {
  237. ajax_return(array(
  238. 'status' => 0,
  239. 'error' => '正在加载视频,请稍后',
  240. ));
  241. }
  242. }
  243. public function video_callback()
  244. {
  245. // {
  246. //   “status”:0, //返回状态,
  247. //   “message”:”” //返回消息,
  248. //   “task”:”transcode” // 文件上传完毕时为file_upload,转码结束时为transcode
  249. //   “data”:{
  250. //   “ret”:0 //错误码,
  251. //   “message”:””//消息 ,
  252. //   “file_id” :123445//文件id
  253. //   “image_video”:{
  254. //   “code”:0,
  255. //   “duration”:0,//持续时间
  256. //   “imgUrl”:{
  257. // “id”: 3213,
  258. //   “url”:”www.qcloud.com/templurl.png”, //图片链接
  259. //   “vheight”:21,
  260. //   “width”:32,
  261. //   }
  262. //   }
  263. //   “message”:””,//消息
  264. //   “vid”:”231414” ,//视频id,
  265. //   “videoUrls”:[
  266. //   {
  267. //   “url”:”www.qcloucd.com/temp_video.mp4”,
  268. //   “md5”:”fdasfdsafsadf”,//md5值
  269. //   “sha”:”dasfdsfas”,//文件sha值,
  270. //   “size”:123 ,//大小
  271. //   “update_time”:”2015 08 49 12:0:0”, //更新时间
  272. //   “vbirate”:231,//比特率
  273. //   “vheight”: 480 ,/ /视频高度
  274. //   “vwidth”:800 ,//视频宽度
  275. //
  276. // }
  277. //   ]
  278. //   “player_code” :{
  279. // “h5”:”” ,//html5播放器代码,
  280. //   “flash”:””,//flash播放器代码,
  281. //   “iframe”:””,//iframe播放器代码
  282. //   }
  283. //   }
  284. // }
  285. //
  286. fanwe_require(APP_ROOT_PATH . 'mapi/lib/tools/PushLog.class.php');
  287. PushLog::log($_REQUEST);
  288. }
  289. }