AdminController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Ellisran
  5. * Date: 2016/9/21
  6. * Time: 16:05
  7. */
  8. class AdminController extends DooController {
  9. public $data;
  10. // public $appKey = '';
  11. // public $AppSecret = '';
  12. function __construct() {
  13. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  14. include ('./protected/controller/BaseController.php');
  15. $this->base = new BaseController ();
  16. $this->base->admin_init();
  17. // require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
  18. // $video = new video ( );
  19. }
  20. /**
  21. * 用户登出
  22. */
  23. function admin_exit() {
  24. setcookie ( "auth_main", "", time () + 3600 * 24, "/", COOKIE_WEB_SITE );
  25. $this->render ( "admin-login", $this->data, TRUE);
  26. }
  27. /**
  28. * 用户管理
  29. */
  30. public function userlist(){
  31. Doo::loadModel('user');
  32. Doo::loadModel('classuser');
  33. $user = new User();
  34. $class_user = new Classuser();
  35. $totalArchive = $user->count();
  36. if(isset($this->params['status'])){
  37. $pager = new DooPager(Doo::conf()->APP_URL . "m/userlist/status/".$this->params['status']."/page", $totalArchive, 20, 10);
  38. }else{
  39. $pager = new DooPager(Doo::conf()->APP_URL . "m/userlist/page", $totalArchive, 20, 10);
  40. }
  41. if (isset($this->params['pindex']))
  42. $pager->paginate(intval($this->params['pindex']));
  43. else
  44. $pager->paginate(1);
  45. if ($pager->limit != ' -20,20')
  46. if(isset($this->params['status'])){
  47. $this->data['userlist'] = $user->getResultbysort($this->params['status'],$pager->limit);
  48. $this->data['status'] = $this->params['status'];
  49. }else{
  50. $this->data['userlist'] = $user->getAllRow($pager->limit);
  51. }
  52. if(isset($this->data['userlist']) && !empty($this->data['userlist'])){
  53. foreach($this->data['userlist'] as $k => $v){
  54. $cnum = $class_user->getNumbyuserid($v['userid']);
  55. $this->data['userlist'][$k]['cnum'] = $cnum;
  56. $this->data['userlist'][$k]['allprice'] = $class_user->getAllpricebyid($v['userid']);
  57. $idcard = strlen($v['idcard'])==15?substr_replace($v['idcard'],"******",2,6):(strlen($v['idcard'])==18?substr_replace($v['idcard'],"*********",3,9):"身份证位数不正常!");
  58. $this->data['userlist'][$k]['idcard'] = $idcard;
  59. }
  60. }
  61. $this->data['pager'] = $pager->output;
  62. $this->data['user'] = TRUE;
  63. $this->render ( "admin-userlist", $this->data, TRUE);
  64. }
  65. /**
  66. * 搜索用户
  67. */
  68. public function userSearch(){
  69. if(isset($_POST['search']) && !empty($_POST['search'])){
  70. Doo::loadModel('user');
  71. $user = new User();
  72. if(is_numeric(trim($_POST['search'])) && strlen(trim($_POST['search'])) == 6){
  73. $result = $user->getUserMsgbyidcard(trim($_POST['search']));
  74. }else{
  75. $result = $user->getUserMsgbySearch(trim($_POST['search']));
  76. }
  77. if(!empty($result)) {
  78. $this->data['userinfo'] = $result;
  79. Doo::loadModel('classuser');
  80. $class_user = new Classuser();
  81. $classlist = $class_user->getclassbyuserid($result['userid']);
  82. if(!empty($classlist)){
  83. $this->data['classlist'] = $classlist;
  84. Doo::loadModel('ktclass');
  85. $ktclass = new Ktclass();
  86. foreach($classlist as $k => $v){
  87. $bum = $class_user->getNumbyClassid($v['classid']);
  88. $this->data['classlist'][$k]['bnum'] = $bum;
  89. $classinfo = $ktclass->getRowbyId($v['classid']);
  90. $hadbuy = $class_user->gethasbyuserandclass($result['userid'],$v['classid']);
  91. $this->data['classlist'][$k]['user_progress'] = $this->getPersonProgress($classinfo,$hadbuy);
  92. $this->data['classlist'][$k]['classname'] = $classinfo['classname'];
  93. $this->data['classlist'][$k]['cnum'] = $classinfo['classnum'];
  94. $this->data['classlist'][$k]['totalnum'] = sprintf('%.2f',$classinfo['classnum']*$classinfo['classtime']/60);
  95. }
  96. }
  97. }else{
  98. $this->data['search'] = $_POST['search'];
  99. }
  100. $this->render('admin-usersearch', $this->data, TRUE);
  101. }else{
  102. return '/m/userlist';
  103. }
  104. }
  105. /**
  106. * 继续教育管理
  107. */
  108. public function classlist(){
  109. Doo::loadModel('ktclass');
  110. Doo::loadModel('classuser');
  111. Doo::loadHelper('DooPager');
  112. $ktclass = new Ktclass();
  113. $class_user = new Classuser();
  114. $totalArchive = $ktclass->count();
  115. $pager = new DooPager(Doo::conf()->APP_URL . "m/classlist/page", $totalArchive, 8, 10);
  116. if (isset($this->params['pindex']))
  117. $pager->paginate(intval($this->params['pindex']));
  118. else
  119. $pager->paginate(1);
  120. if ($pager->limit != ' -8,8')
  121. $this->data['classlist'] = $ktclass->getclasslist($pager->limit);
  122. foreach($this->data['classlist'] as $k => $v){
  123. $bum = $class_user->getNumbyClassid($v['classid']);
  124. $this->data['classlist'][$k]['bnum'] = $bum;
  125. }
  126. $this->data['pager'] = $pager->output;
  127. $this->data['jiaoyu'] = TRUE;
  128. $this->render ( "admin-classlist", $this->data, TRUE);
  129. }
  130. /**
  131. * 课程进度
  132. */
  133. public function tracklist(){
  134. Doo::loadModel('ktclass');
  135. Doo::loadModel('classuser');
  136. Doo::loadHelper('DooPager');
  137. $ktclass = new Ktclass();
  138. $class_user = new Classuser();
  139. $totalArchive = $ktclass->count(array('where' => 'ishow=1'));
  140. $pager = new DooPager(Doo::conf()->APP_URL . "m/tracklist/page", $totalArchive, 8, 10);
  141. if (isset($this->params['pindex']))
  142. $pager->paginate(intval($this->params['pindex']));
  143. else
  144. $pager->paginate(1);
  145. if ($pager->limit != ' -8,8')
  146. $this->data['classlist'] = $ktclass->getclasslistbyshow($pager->limit);
  147. foreach($this->data['classlist'] as $k => $v){
  148. $bum = $class_user->getNumbyClassid($v['classid']);
  149. $this->data['classlist'][$k]['bnum'] = $bum;
  150. $this->data['classlist'][$k]['totalnum'] = sprintf('%.2f',$v['classnum']*$v['classtime']/60);
  151. $this->data['classlist'][$k]['class_progress'] = $this->getClassProgress($v['classid'],$this->data['classlist'][$k]['totalnum'],$bum);
  152. }
  153. $this->data['pager'] = $pager->output;
  154. $this->data['kecheng'] = TRUE;
  155. $this->render ( "admin-classtracklist", $this->data, TRUE);
  156. }
  157. public function trackInfo(){
  158. Doo::loadModel('ktclass');
  159. Doo::loadModel('user');
  160. Doo::loadModel('classuser');
  161. Doo::loadHelper('DooPager');
  162. $ktclass = new Ktclass();
  163. $class_user = new Classuser();
  164. $user = new User();
  165. $class = $ktclass->getRowbyId($this->params['classid']);
  166. $this->data['totalnum'] = sprintf("%.2f", $class['classnum']*$class['classtime']/60);
  167. $this->data['classname'] = $ktclass->getnamebyId($this->params['classid'])['classname'];
  168. $this->data['classid'] = $this->params['classid'];
  169. $totalArchive = $class_user->getNumbyClassid($this->params['classid']);
  170. if(isset($this->params['sort'])){
  171. $pager = new DooPager(Doo::conf()->APP_URL . "m/trackinfo/".$this->params['classid']."/sort/".$this->params['sort']."/page", $totalArchive, 20, 10);
  172. }else{
  173. $pager = new DooPager(Doo::conf()->APP_URL . "m/trackinfo/".$this->params['classid']."/page", $totalArchive, 20, 10);
  174. }
  175. if (isset($this->params['pindex']))
  176. $pager->paginate(intval($this->params['pindex']));
  177. else
  178. $pager->paginate(1);
  179. if ($pager->limit != ' -20,20'){
  180. if(isset($this->params['sort'])){
  181. $this->data['userlist'] = $class_user->getuserlist2($this->params['classid'],$pager->limit,$this->params['sort']);
  182. $this->data['sort'] = $this->params['sort'];
  183. }else{
  184. $this->data['userlist'] = $class_user->getuserlist($this->params['classid'],$pager->limit);
  185. }
  186. }
  187. if(isset($this->data['userlist'])){
  188. foreach($this->data['userlist'] as $k => $v){
  189. $this->data['userlist'][$k]['username'] = $user->getNamebyId($v['userid'])['username'];
  190. $hadbuy = $class_user->gethasbyuserandclass($v['userid'],$this->params['classid']);
  191. $this->data['userlist'][$k]['user_progress'] = $this->getPersonProgress($class,$hadbuy);
  192. }
  193. }
  194. $this->data['pager'] = $pager->output;
  195. $this->render('admin-classtrack', $this->data, true);
  196. }
  197. //进度课程搜索
  198. public function trackSearch(){
  199. if(isset($_POST['search']) && !empty($_POST['search'])){
  200. Doo::loadModel('ktclass');
  201. Doo::loadModel('classuser');
  202. $ktclass = new Ktclass();
  203. $class_user = new Classuser();
  204. $this->data['classlist'] = $ktclass->getclassbySearch($_POST['search']);
  205. if(!empty($this->data['classlist'])){
  206. foreach($this->data['classlist'] as $k => $v){
  207. $bum = $class_user->getNumbyClassid($v['classid']);
  208. $this->data['classlist'][$k]['bnum'] = $bum;
  209. $this->data['classlist'][$k]['totalnum'] = $v['classnum']*($v['classtime']/60);
  210. $this->data['classlist'][$k]['class_progress'] = $this->getClassProgress($v['classid'],$this->data['classlist'][$k]['totalnum'],$bum);
  211. }
  212. }else{
  213. $this->data['searchResult'] = $_POST['search'];
  214. }
  215. $this->data['kecheng'] = TRUE;
  216. $this->render ( "admin-classtracklist", $this->data, TRUE);
  217. }else{
  218. return '/m/tracklist';
  219. }
  220. }
  221. /**
  222. * 订单列表
  223. */
  224. public function orderlist(){
  225. Doo::loadModel('order');
  226. Doo::loadHelper('DooPager');
  227. $ktorder = new Order();
  228. if(isset($this->params['search']) && !empty($this->params['search']) && !isset($this->params['status'])){
  229. $search = urldecode(trim($this->params['search']));
  230. $totalArchive = $ktorder->count(array('where' => 'trade_sn=? or username=? or useremail=? or mobile=? or classname=?', 'param' => array($search,$search,$search,$search,$search), 'asArray' => TRUE));
  231. $pager = new DooPager(Doo::conf()->APP_URL . "m/orderinfo/result/".$search."/page", $totalArchive, 20, 10);
  232. if (isset($this->params['pindex']))
  233. $pager->paginate(intval($this->params['pindex']));
  234. else
  235. $pager->paginate(1);
  236. if ($pager->limit != ' -20,20')
  237. $this->data['orderlist'] = $ktorder->getorderlistbySearch($search, $pager->limit);
  238. $this->data['search'] = $search;
  239. }elseif(isset($this->params['search']) && !empty($this->params['search']) && isset($this->params['status']) && !empty($this->params['status'])){
  240. $search = urldecode(trim($this->params['search']));
  241. $totalArchive = $ktorder->count(array('where' => '(trade_sn=? or username=? or useremail=? or mobile=? or classname=?) and status=?', 'param' => array($search,$search,$search,$search,$search,$this->params['status']), 'asArray' => TRUE));
  242. $pager = new DooPager(Doo::conf()->APP_URL . "m/orderinfo/status/".$this->params['status']."/result/".$search."/page", $totalArchive, 20, 10);
  243. if (isset($this->params['pindex']))
  244. $pager->paginate(intval($this->params['pindex']));
  245. else
  246. $pager->paginate(1);
  247. if ($pager->limit != ' -20,20')
  248. $this->data['orderlist'] = $ktorder->getorderlistbySearch($search, $pager->limit, $this->params['status']);
  249. $this->data['search'] = $search;
  250. $this->data['status'] = $this->params['status'];
  251. }elseif(isset($this->params['status']) && !empty($this->params['status']) && !isset($this->params['search'])){
  252. $totalArchive = $ktorder->count(array('where' => 'status='.$this->params['status'], 'asArray' => TRUE));
  253. $pager = new DooPager(Doo::conf()->APP_URL . "m/orderlist/status/".$this->params['status']."/page", $totalArchive, 20, 10);
  254. if (isset($this->params['pindex']))
  255. $pager->paginate(intval($this->params['pindex']));
  256. else
  257. $pager->paginate(1);
  258. if ($pager->limit != ' -20,20')
  259. $this->data['orderlist'] = $ktorder->getorderlist($pager->limit,$this->params['status']);
  260. $this->data['status'] = $this->params['status'];
  261. }else{
  262. $totalArchive = $ktorder->count();
  263. $pager = new DooPager(Doo::conf()->APP_URL . "m/orderlist/page", $totalArchive, 20, 10);
  264. if (isset($this->params['pindex']))
  265. $pager->paginate(intval($this->params['pindex']));
  266. else
  267. $pager->paginate(1);
  268. if ($pager->limit != ' -20,20')
  269. $this->data['orderlist'] = $ktorder->getorderlist($pager->limit);
  270. }
  271. if(isset($this->data['orderlist'])){
  272. foreach($this->data['orderlist'] as $k => $v){
  273. $this->data['orderlist'][$k]['createtime'] = date('Y-m-d H:i',$v['createtime']);
  274. }
  275. }
  276. $this->data['pager'] = $pager->output;
  277. $this->data['order'] = TRUE;
  278. $this->render ( "admin-orderlist", $this->data, TRUE);
  279. }
  280. /**
  281. * 发票列表
  282. */
  283. public function receiptlist(){
  284. $this->data['order'] = TRUE;
  285. $this->render ( "admin-receiptlist", $this->data, TRUE);
  286. }
  287. public function upload(){
  288. $this->render('upload', $this->data, TRUE);
  289. }
  290. //添加或编辑课程
  291. public function editClass(){
  292. if(isset($this->params['classid'])){
  293. Doo::loadModel('ktclass');
  294. $ktclass = new Ktclass();
  295. $this->data['classinfo'] = $ktclass->getRowbyId($this->params['classid']);
  296. $this->data['classinfo']['stoptime'] = date("Y-m-d",$this->data['classinfo']['stoptime']);
  297. $this->data['edit'] = true;
  298. }
  299. $this->data['jiaoyu'] = TRUE;
  300. $this->render('admin-editclass', $this->data, true);
  301. }
  302. //添加和编辑课程
  303. public function do_class(){
  304. if(empty($_POST['classname'])){
  305. exit('课程名不能为空');
  306. }
  307. if(empty($_POST['price'])){
  308. exit('价格不能为空');
  309. }
  310. if(empty($_POST['totalnum'])){
  311. exit('总课时不能为空');
  312. }
  313. if(empty($_POST['classtime'])){
  314. exit('课程时长不能为空');
  315. }
  316. if(empty($_POST['stoptime'])){
  317. exit('截止日期不能为空');
  318. }
  319. if(empty($_POST['desc'])){
  320. exit('简介不能为空');
  321. }
  322. $price = $_POST['price'];
  323. $name = $_POST['classname'];
  324. $totalnum = $_POST['totalnum'];
  325. $classtime = $_POST['classtime'];
  326. $stop = strtotime($_POST['stoptime']);
  327. $desc = $_POST['desc'];
  328. if(!empty($_POST['createtime'])){
  329. $createTime = $_POST['createtime'];
  330. }else{
  331. $createTime = time();
  332. }
  333. var_dump($stop);
  334. $avatar = '';
  335. if(!empty($_FILES["avatar"]['name'])){
  336. if ((($_FILES["avatar"]["type"] == "image/gif")
  337. || ($_FILES["avatar"]["type"] == "image/jpeg")
  338. || ($_FILES["avatar"]["type"] == "image/pjpeg")
  339. || ($_FILES["avatar"]["type"] == "image/png"))
  340. && ($_FILES["avatar"]["size"] < 1048576))
  341. {
  342. if ($_FILES["avatar"]["error"] > 0) {
  343. echo "Return Code: " . $_FILES["avatar"]["error"];
  344. return false;
  345. }
  346. else {
  347. include (DOO::conf()->SITE_PATH . 'protected/plugin/io.han.php');
  348. $this->IoHandler = new IoHandler();
  349. $filedir = $createTime;
  350. //调用定义物理路径
  351. $t=DOO::conf()->SITE_PATH."avatar/".$filedir;
  352. // $t='/opt/www/wenku/report/'.$filedir."/thumb";
  353. $this->IoHandler->MakeDir($t);
  354. $upload_dir = $t."/".$createTime.".png";
  355. $k=move_uploaded_file($_FILES["avatar"]["tmp_name"], $upload_dir);
  356. if($k) {
  357. $avatar = 'avatar/'.$createTime.'/'.$createTime.".png";
  358. }
  359. }
  360. }else{
  361. echo '预览图片文件过大或格式不对';
  362. return false;
  363. }
  364. }elseif(empty($_FILES["avatar"]['name']) && empty($_POST['hadavatar'])){
  365. exit('请上传预览图');
  366. }
  367. Doo::loadModel('ktclass');
  368. $ktclass = new Ktclass();
  369. if(isset($_POST['classid']) && !empty($_POST['classid'])){
  370. $ktclass->classid = $_POST['classid'];
  371. $ktclass->classname = $name;
  372. $ktclass->price = $price;
  373. $ktclass->classnum = $totalnum;
  374. $ktclass->classtime = $classtime;
  375. $ktclass->stoptime = $stop;
  376. $ktclass->description = $desc;
  377. $ktclass->update();
  378. }else{
  379. $ktclass->classname = $name;
  380. $ktclass->price = $price;
  381. $ktclass->classnum = $totalnum;
  382. $ktclass->classtime = $classtime;
  383. $ktclass->stoptime = $stop;
  384. $ktclass->description = $desc;
  385. $ktclass->createtime = $createTime;
  386. $ktclass->avatar = $avatar;
  387. $ktclass->ishow = 0;
  388. $ktclass->insert();
  389. }
  390. return '/m/classlist';
  391. }
  392. //发布课程
  393. public function showOnline(){
  394. if(isset($_POST['classid']) && !empty($_POST['classid'])){
  395. Doo::loadModel('ktclass');
  396. $ktclass = new Ktclass();
  397. $ktclass->classid = $_POST['classid'];
  398. $ktclass->ishow = 1;
  399. $result = $ktclass->update();
  400. if($result){
  401. echo '1';
  402. exit();
  403. }
  404. }else{
  405. echo '0';
  406. exit();
  407. }
  408. }
  409. //课程详情页
  410. public function classInfo(){
  411. Doo::loadModel('ktclass');
  412. Doo::loadModel('classuser');
  413. Doo::loadModel('kttype');
  414. $ktclass = new Ktclass();
  415. $ktype = new Kttype();
  416. $class_user = new Classuser();
  417. $this->data['kttype'] = $ktype->getTypebyClassid($this->params['classid']);
  418. foreach($this->data['kttype'] as $k => $v){
  419. Doo::loadModel('ktsection');
  420. $ktsection = new Ktsection();
  421. $section = $ktsection->getSecbyTypeid($v['typeid']);
  422. $this->data['kttype'][$k]['section'] = $section;
  423. foreach($section as $sk => $sv){
  424. Doo::loadModel('ktvideo');
  425. $ktvideo = new Ktvideo();
  426. $video = $ktvideo->getVideobySec($sv['seid']);
  427. $this->data['kttype'][$k]['section'][$sk]['video'] = $video;
  428. }
  429. }
  430. $this->data['bnum'] = $class_user->getNumbyClassid($this->params['classid']);
  431. $this->data['classinfo'] = $ktclass->getRowbyId($this->params['classid']);
  432. $this->data['jiaoyu'] = TRUE;
  433. $this->render('admin-classinfo', $this->data, true);
  434. }
  435. //添加课程里的章
  436. public function addType(){
  437. // require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
  438. // $video = new video ( );
  439. $typeprefix = $_POST['typeprefix'];
  440. $typeName = $_POST['typename'];
  441. $classid = $_POST['classid'];
  442. if($typeprefix == '' || $typeName == ''){
  443. exit('请输入章号或章名!');
  444. }
  445. // $data = $video->videoTypeCreate($typeName);
  446. // if($data['code'] == '200'){
  447. // $video_type_id = $data['ret']['typeId'];
  448. // }else{
  449. // exit('网易视频云 - 创建分类失败,请联系管理员');
  450. // }
  451. Doo::loadModel('kttype');
  452. $kttype = new Kttype();
  453. $kttype->typeprefix = $typeprefix;
  454. $kttype->typename = $typeName;
  455. // $kttype->video_typeid = $video_type_id;
  456. $kttype->createtime = time();
  457. $kttype->classid = $classid;
  458. $kttype->insert();
  459. return '/m/classinfo/'.$classid;
  460. }
  461. //编辑章
  462. public function ExitType(){
  463. // require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
  464. // $video = new video ( );
  465. $typeprefix = $_POST['exprefix'];
  466. $typeName = $_POST['typename'];
  467. $classid = $_POST['classid'];
  468. $typeid = $_POST['typeid'];
  469. // $wytypeid = $_POST['wytypeid'];
  470. if($typeprefix == '' || $typeName == ''){
  471. exit('请输入章号或章名!');
  472. }
  473. // $data = $video->videoTypeUpdate($wytypeid, $typeName);
  474. // if($data['code'] == '200'){
  475. Doo::loadModel('kttype');
  476. $kttype = new Kttype();
  477. $kttype->typeprefix = $typeprefix;
  478. $kttype->typename = $typeName;
  479. $kttype->typeid = $typeid;
  480. $kttype->update();
  481. // }else{
  482. // exit('网易视频云 - 修改分类失败,请联系管理员');
  483. // }
  484. return '/m/classinfo/'.$classid;
  485. }
  486. //删除章
  487. public function deleteType(){
  488. // require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
  489. // $video = new video ( );
  490. $classid = $this->params['classid'];
  491. $typeid = $this->params['typeid'];
  492. Doo::loadModel('kttype');
  493. $kttype = new Kttype();
  494. // $wytype = $kttype->getwyidBytypeid($typeid);
  495. // $data = $video->videoTypeDelete($wytype['video_typeid']);
  496. // if($data['code'] == '200'){
  497. $kttype->typeid = $typeid;
  498. $kttype->delete();
  499. Doo::loadModel('ktsection');
  500. $ktsection = new Ktsection();
  501. $section = $ktsection->getSecbyTypeid($typeid);
  502. foreach($section as $k => $v){
  503. $ktsection->seid = $v['seid'];
  504. $ktsection->delete();
  505. }
  506. // }else{
  507. // exit('网易视频云 - 删除分类失败,请联系管理员');
  508. // }
  509. return '/m/classinfo/'.$classid;
  510. }
  511. //添加章里的节
  512. public function addSection(){
  513. $seprefix = $_POST['seprefix'];
  514. $seName = $_POST['sename'];
  515. $typeid = $_POST['typeid'];
  516. $classid = $_POST['classid'];
  517. if($seprefix == '' || $seName == ''){
  518. exit('请输入节号或节名!');
  519. }
  520. Doo::loadModel('ktsection');
  521. $ktsection = new Ktsection();
  522. $ktsection->seprefix = $seprefix;
  523. $ktsection->sename = $seName;
  524. $ktsection->createtime = time();
  525. $ktsection->typeid = $typeid;
  526. $ktsection->insert();
  527. return '/m/classinfo/'.$classid;
  528. }
  529. public function exitSection(){
  530. $seprefix = $_POST['seprefix'];
  531. $seName = $_POST['sename'];
  532. $ishow = $_POST['sectionshow'];
  533. $seid = $_POST['seid'];
  534. $classid = $_POST['classid'];
  535. if($seprefix == '' || $seName == ''){
  536. exit('请输入节号或节名!');
  537. }
  538. Doo::loadModel('ktsection');
  539. $ktsection = new Ktsection();
  540. $ktsection->seprefix = $seprefix;
  541. $ktsection->sename = $seName;
  542. $ktsection->ishow = $ishow;
  543. $ktsection->seid = $seid;
  544. $ktsection->update();
  545. return '/m/classinfo/'.$classid;
  546. }
  547. //删除节
  548. public function deleteSection(){
  549. $seid = $this->params['seid'];
  550. $classid = $this->params['classid'];
  551. Doo::loadModel('ktsection');
  552. $ktsection = new Ktsection();
  553. $ktsection->seid = $seid;
  554. $ktsection->delete();
  555. return '/m/classinfo/'.$classid;
  556. }
  557. //添加视频
  558. public function addVideo(){
  559. if(isset($_POST['videomsg']) && !empty($_POST['videomsg'])){
  560. $videodata = $_POST['videomsg'];
  561. require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
  562. $video = new video ( );
  563. $result = $video->videoGet($videodata['wyvideoid']);
  564. if($result['code'] == 200){
  565. Doo::loadModel('ktvideo');
  566. $ktvideo = new Ktvideo();
  567. $ktvideo->videoname = basename($videodata['fileName'],".".substr(strrchr($videodata['fileName'], '.'), 1));//不带后缀的视频名
  568. $ktvideo->objectname = $videodata['objectname'];
  569. $ktvideo->wy_video_id = $videodata['wyvideoid'];
  570. $ktvideo->classid = $videodata['classid'];
  571. $ktvideo->typeid = $videodata['typeid'];
  572. $ktvideo->seid = $videodata['seid'];
  573. $ktvideo->type_video_id = 27143;
  574. $ktvideo->file_time = $result['ret']['duration'];
  575. $ktvideo->file_ext = $videodata['ext'];
  576. $ktvideo->file_size = $videodata['size'];
  577. $ktvideo->isshow = 0;
  578. $ktvideo->addtime = time();
  579. $res = $ktvideo->insert();
  580. }
  581. }else{
  582. echo 0;
  583. exit();
  584. }
  585. }
  586. //修改视频
  587. public function updateVideo(){
  588. if(isset($_POST['videoId']) && !empty($_POST['videoId'])){
  589. $videoid = $_POST['videoId'];
  590. Doo::loadModel('ktvideo');
  591. $ktvideo = new Ktvideo();
  592. $wyvideo = $ktvideo->getvideobyid($videoid);
  593. if(!empty($wyvideo)){
  594. $ktvideo->videoid = $_POST['videoId'];
  595. $ktvideo->videoname = $_POST['videoName'];
  596. $ktvideo->isshow = $_POST['isshow'];
  597. $ktvideo->update();
  598. $section = $ktvideo->getsecbyid($_POST['videoId']);
  599. $num = $ktvideo->count(array('where' => 'seid='.$section['seid'],'asArray'));
  600. if($num == 1){
  601. Doo::loadModel('ktsection');
  602. $ktsection = new Ktsection();
  603. if($_POST['isshow'] == 1){
  604. $ktsection->ishow = 1;
  605. }else{
  606. $ktsection->ishow = 0;
  607. }
  608. $ktsection->seid = $section['seid'];
  609. $ktsection->update();
  610. }
  611. require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
  612. $video = new video ( );
  613. $result = $video->videoEdit($wyvideo['wy_video_id'],$_POST['videoName'].'.'.$wyvideo['file_ext'],$wyvideo['type_video_id']);
  614. if($result['code'] == 200){
  615. return '/m/classinfo/'.$_POST['classid'];
  616. }else{
  617. return '/m/classinfo/'.$_POST['classid'];
  618. }
  619. }else{
  620. return '/m/classinfo/'.$_POST['classid'];
  621. }
  622. }else{
  623. return '/m/classinfo/'.$_POST['classid'];
  624. }
  625. }
  626. //发布视频
  627. public function showVideo(){
  628. $videoid = $this->params['videoid'];
  629. $classid = $this->params['classid'];
  630. Doo::loadModel('ktvideo');
  631. $ktvideo = new Ktvideo();
  632. $section = $ktvideo->getsecbyid($videoid);
  633. $num = $ktvideo->count(array('where' => 'seid='.$section['seid'],'asArray'));
  634. if($num == 1){
  635. Doo::loadModel('ktsection');
  636. $ktsection = new Ktsection();
  637. $ktsection->ishow = 1;
  638. $ktsection->seid = $section['seid'];
  639. $ktsection->update();
  640. }
  641. $ktvideo->videoid = $videoid;
  642. $ktvideo->isshow = 1;
  643. $ktvideo->update();
  644. return '/m/classinfo/'.$classid;
  645. }
  646. //判断视频是否可以发布
  647. public function isShowVideo(){
  648. require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
  649. $video = new video ( );
  650. $result = $video->videoGet($_GET['video']);
  651. if($result['code'] == 200) {
  652. if(empty($result['ret']['shdMp4Url'])){
  653. echo '0';
  654. exit;
  655. }else{
  656. echo '1';
  657. exit;
  658. }
  659. }else{
  660. echo '0';
  661. exit;
  662. }
  663. }
  664. //删除视频
  665. public function delVideo(){
  666. $videoid = $this->params['videoid'];
  667. $classid = $this->params['classid'];
  668. Doo::loadModel('ktvideo');
  669. $ktvideo = new Ktvideo();
  670. $result = $ktvideo->getvideobyid($videoid);
  671. if(!empty($result)) {
  672. require_once(Doo::conf()->SITE_PATH . '/protected/class/video.php');
  673. $video = new video ( );
  674. $delvideo = $video->videoDetele($result['wy_video_id']);
  675. $ktvideo->videoid = $videoid;
  676. $ktvideo->delete();
  677. }
  678. return '/m/classinfo/'.$classid;
  679. }
  680. //播放转码后视频
  681. public function playVideo(){
  682. require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
  683. $video = new video ( );
  684. if(isset($_GET['video'])){
  685. $result = $video->videoGet($_GET['video']);
  686. if($result['code'] == 200){
  687. $play_url = !empty($result['ret']['shdMp4Url']) ? $result['ret']['shdMp4Url'] : '';
  688. $play_type = substr(strrchr($play_url, '.'), 1);
  689. if ($play_type == 'mp4'){
  690. $type = 'video/mp4';
  691. }else {
  692. echo json_encode(array( 'code' => 400));
  693. exit;
  694. }
  695. echo json_encode(array( 'code' => 200, 'url' => $play_url, 'type' => $type));
  696. exit;
  697. }
  698. echo json_encode(array( 'code' => 400));
  699. exit;
  700. }
  701. echo json_encode(array( 'code' => 400));
  702. exit;
  703. }
  704. //获取个人的学习进度
  705. private function getPersonProgress($class,$classuser){
  706. $totalss = $class['classnum']*$class['classtime']*60; //课程总秒数
  707. $userss = $classuser['seetime']; //已完成的秒数
  708. $nodonehh = sprintf('%.2f',($totalss-$userss)/3600); //未完成的小时数
  709. $donehh = sprintf('%.2f',$classuser['seetime']/3600); //已完成的小时数
  710. $doneclassnum = intval($userss/($class['classtime']*60)); //已完成的课时数,取整
  711. if($doneclassnum<10 && $doneclassnum != 0){
  712. $doneclassnum = '0'.$doneclassnum;
  713. }
  714. $progress = sprintf('%.2f',$userss/$totalss) *100; //已完成占总课程的百分比showVideo
  715. $noprogress = 100-$progress; //未完成占总课程的百分比
  716. return array('progress' => $progress, 'noprogress' => $noprogress, 'donehh' => $donehh, 'doneclassnum' => $doneclassnum, 'nodonehh' => $nodonehh);
  717. }
  718. //获取课程的平均进度
  719. private function getClassProgress($classid,$totalnum,$bnum){
  720. if($bnum != 0){
  721. Doo::loadModel('classuser');
  722. $classuser = new Classuser();
  723. $classtrack = $classuser->gettimebyClassid($classid);
  724. $doness = 0;
  725. foreach($classtrack as $k => $v){
  726. $doness += $v['seetime']; //已完成的总秒数
  727. }
  728. $donehh = sprintf('%.2f',sprintf('%.2f',$doness/3600)/$bnum); //已完成的平均小时数
  729. $nodonehh = $totalnum-$donehh; //未完成的小时数
  730. $progress = sprintf('%.2f',$donehh/$totalnum) *100; //已完成占总课程的百分比
  731. $noprogress = 100-$progress; //未完成占总课程的百分比
  732. }else{
  733. $progress = 0;
  734. $noprogress = 100;
  735. $donehh = 0;
  736. $nodonehh = $totalnum;
  737. }
  738. return array('progress' => $progress, 'noprogress' => $noprogress, 'donehh' => $donehh, 'nodonehh' => $nodonehh);
  739. }
  740. }