123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Ellisran
- * Date: 2016/9/21
- * Time: 16:05
- */
- class AdminController extends DooController {
- public $data;
- // public $appKey = '';
- // public $AppSecret = '';
- function __construct() {
- $this->data['rootUrl'] = Doo::conf()->APP_URL;
- include ('./protected/controller/BaseController.php');
- $this->base = new BaseController ();
- $this->base->admin_init();
- // require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
- // $video = new video ( );
- }
- /**
- * 用户登出
- */
- function admin_exit() {
- setcookie ( "auth_main", "", time () + 3600 * 24, "/", COOKIE_WEB_SITE );
- $this->render ( "admin-login", $this->data, TRUE);
- }
- /**
- * 用户管理
- */
- public function userlist(){
- Doo::loadModel('user');
- Doo::loadModel('classuser');
- $user = new User();
- $class_user = new Classuser();
- $totalArchive = $user->count();
- if(isset($this->params['status'])){
- $pager = new DooPager(Doo::conf()->APP_URL . "m/userlist/status/".$this->params['status']."/page", $totalArchive, 20, 10);
- }else{
- $pager = new DooPager(Doo::conf()->APP_URL . "m/userlist/page", $totalArchive, 20, 10);
- }
- if (isset($this->params['pindex']))
- $pager->paginate(intval($this->params['pindex']));
- else
- $pager->paginate(1);
- if ($pager->limit != ' -20,20')
- if(isset($this->params['status'])){
- $this->data['userlist'] = $user->getResultbysort($this->params['status'],$pager->limit);
- $this->data['status'] = $this->params['status'];
- }else{
- $this->data['userlist'] = $user->getAllRow($pager->limit);
- }
- if(isset($this->data['userlist']) && !empty($this->data['userlist'])){
- foreach($this->data['userlist'] as $k => $v){
- $cnum = $class_user->getNumbyuserid($v['userid']);
- $this->data['userlist'][$k]['cnum'] = $cnum;
- $this->data['userlist'][$k]['allprice'] = $class_user->getAllpricebyid($v['userid']);
- $idcard = strlen($v['idcard'])==15?substr_replace($v['idcard'],"******",2,6):(strlen($v['idcard'])==18?substr_replace($v['idcard'],"*********",3,9):"身份证位数不正常!");
- $this->data['userlist'][$k]['idcard'] = $idcard;
- }
- }
- $this->data['pager'] = $pager->output;
- $this->data['user'] = TRUE;
- $this->render ( "admin-userlist", $this->data, TRUE);
- }
- /**
- * 搜索用户
- */
- public function userSearch(){
- if(isset($_POST['search']) && !empty($_POST['search'])){
- Doo::loadModel('user');
- $user = new User();
- if(is_numeric(trim($_POST['search'])) && strlen(trim($_POST['search'])) == 6){
- $result = $user->getUserMsgbyidcard(trim($_POST['search']));
- }else{
- $result = $user->getUserMsgbySearch(trim($_POST['search']));
- }
- if(!empty($result)) {
- $this->data['userinfo'] = $result;
- Doo::loadModel('classuser');
- $class_user = new Classuser();
- $classlist = $class_user->getclassbyuserid($result['userid']);
- if(!empty($classlist)){
- $this->data['classlist'] = $classlist;
- Doo::loadModel('ktclass');
- $ktclass = new Ktclass();
- foreach($classlist as $k => $v){
- $bum = $class_user->getNumbyClassid($v['classid']);
- $this->data['classlist'][$k]['bnum'] = $bum;
- $classinfo = $ktclass->getRowbyId($v['classid']);
- $hadbuy = $class_user->gethasbyuserandclass($result['userid'],$v['classid']);
- $this->data['classlist'][$k]['user_progress'] = $this->getPersonProgress($classinfo,$hadbuy);
- $this->data['classlist'][$k]['classname'] = $classinfo['classname'];
- $this->data['classlist'][$k]['cnum'] = $classinfo['classnum'];
- $this->data['classlist'][$k]['totalnum'] = sprintf('%.2f',$classinfo['classnum']*$classinfo['classtime']/60);
- }
- }
- }else{
- $this->data['search'] = $_POST['search'];
- }
- $this->render('admin-usersearch', $this->data, TRUE);
- }else{
- return '/m/userlist';
- }
- }
- /**
- * 继续教育管理
- */
- public function classlist(){
- Doo::loadModel('ktclass');
- Doo::loadModel('classuser');
- Doo::loadHelper('DooPager');
- $ktclass = new Ktclass();
- $class_user = new Classuser();
- $totalArchive = $ktclass->count();
- $pager = new DooPager(Doo::conf()->APP_URL . "m/classlist/page", $totalArchive, 8, 10);
- if (isset($this->params['pindex']))
- $pager->paginate(intval($this->params['pindex']));
- else
- $pager->paginate(1);
- if ($pager->limit != ' -8,8')
- $this->data['classlist'] = $ktclass->getclasslist($pager->limit);
- foreach($this->data['classlist'] as $k => $v){
- $bum = $class_user->getNumbyClassid($v['classid']);
- $this->data['classlist'][$k]['bnum'] = $bum;
- }
- $this->data['pager'] = $pager->output;
- $this->data['jiaoyu'] = TRUE;
- $this->render ( "admin-classlist", $this->data, TRUE);
- }
- /**
- * 课程进度
- */
- public function tracklist(){
- Doo::loadModel('ktclass');
- Doo::loadModel('classuser');
- Doo::loadHelper('DooPager');
- $ktclass = new Ktclass();
- $class_user = new Classuser();
- $totalArchive = $ktclass->count(array('where' => 'ishow=1'));
- $pager = new DooPager(Doo::conf()->APP_URL . "m/tracklist/page", $totalArchive, 8, 10);
- if (isset($this->params['pindex']))
- $pager->paginate(intval($this->params['pindex']));
- else
- $pager->paginate(1);
- if ($pager->limit != ' -8,8')
- $this->data['classlist'] = $ktclass->getclasslistbyshow($pager->limit);
- foreach($this->data['classlist'] as $k => $v){
- $bum = $class_user->getNumbyClassid($v['classid']);
- $this->data['classlist'][$k]['bnum'] = $bum;
- $this->data['classlist'][$k]['totalnum'] = sprintf('%.2f',$v['classnum']*$v['classtime']/60);
- $this->data['classlist'][$k]['class_progress'] = $this->getClassProgress($v['classid'],$this->data['classlist'][$k]['totalnum'],$bum);
- }
- $this->data['pager'] = $pager->output;
- $this->data['kecheng'] = TRUE;
- $this->render ( "admin-classtracklist", $this->data, TRUE);
- }
- public function trackInfo(){
- Doo::loadModel('ktclass');
- Doo::loadModel('user');
- Doo::loadModel('classuser');
- Doo::loadHelper('DooPager');
- $ktclass = new Ktclass();
- $class_user = new Classuser();
- $user = new User();
- $class = $ktclass->getRowbyId($this->params['classid']);
- $this->data['totalnum'] = sprintf("%.2f", $class['classnum']*$class['classtime']/60);
- $this->data['classname'] = $ktclass->getnamebyId($this->params['classid'])['classname'];
- $this->data['classid'] = $this->params['classid'];
- $totalArchive = $class_user->getNumbyClassid($this->params['classid']);
- if(isset($this->params['sort'])){
- $pager = new DooPager(Doo::conf()->APP_URL . "m/trackinfo/".$this->params['classid']."/sort/".$this->params['sort']."/page", $totalArchive, 20, 10);
- }else{
- $pager = new DooPager(Doo::conf()->APP_URL . "m/trackinfo/".$this->params['classid']."/page", $totalArchive, 20, 10);
- }
- if (isset($this->params['pindex']))
- $pager->paginate(intval($this->params['pindex']));
- else
- $pager->paginate(1);
- if ($pager->limit != ' -20,20'){
- if(isset($this->params['sort'])){
- $this->data['userlist'] = $class_user->getuserlist2($this->params['classid'],$pager->limit,$this->params['sort']);
- $this->data['sort'] = $this->params['sort'];
- }else{
- $this->data['userlist'] = $class_user->getuserlist($this->params['classid'],$pager->limit);
- }
- }
- if(isset($this->data['userlist'])){
- foreach($this->data['userlist'] as $k => $v){
- $this->data['userlist'][$k]['username'] = $user->getNamebyId($v['userid'])['username'];
- $hadbuy = $class_user->gethasbyuserandclass($v['userid'],$this->params['classid']);
- $this->data['userlist'][$k]['user_progress'] = $this->getPersonProgress($class,$hadbuy);
- }
- }
- $this->data['pager'] = $pager->output;
- $this->render('admin-classtrack', $this->data, true);
- }
- //进度课程搜索
- public function trackSearch(){
- if(isset($_POST['search']) && !empty($_POST['search'])){
- Doo::loadModel('ktclass');
- Doo::loadModel('classuser');
- $ktclass = new Ktclass();
- $class_user = new Classuser();
- $this->data['classlist'] = $ktclass->getclassbySearch($_POST['search']);
- if(!empty($this->data['classlist'])){
- foreach($this->data['classlist'] as $k => $v){
- $bum = $class_user->getNumbyClassid($v['classid']);
- $this->data['classlist'][$k]['bnum'] = $bum;
- $this->data['classlist'][$k]['totalnum'] = $v['classnum']*($v['classtime']/60);
- $this->data['classlist'][$k]['class_progress'] = $this->getClassProgress($v['classid'],$this->data['classlist'][$k]['totalnum'],$bum);
- }
- }else{
- $this->data['searchResult'] = $_POST['search'];
- }
- $this->data['kecheng'] = TRUE;
- $this->render ( "admin-classtracklist", $this->data, TRUE);
- }else{
- return '/m/tracklist';
- }
- }
- /**
- * 订单列表
- */
- public function orderlist(){
- Doo::loadModel('order');
- Doo::loadHelper('DooPager');
- $ktorder = new Order();
- if(isset($this->params['search']) && !empty($this->params['search']) && !isset($this->params['status'])){
- $search = urldecode(trim($this->params['search']));
- $totalArchive = $ktorder->count(array('where' => 'trade_sn=? or username=? or useremail=? or mobile=? or classname=?', 'param' => array($search,$search,$search,$search,$search), 'asArray' => TRUE));
- $pager = new DooPager(Doo::conf()->APP_URL . "m/orderinfo/result/".$search."/page", $totalArchive, 20, 10);
- if (isset($this->params['pindex']))
- $pager->paginate(intval($this->params['pindex']));
- else
- $pager->paginate(1);
- if ($pager->limit != ' -20,20')
- $this->data['orderlist'] = $ktorder->getorderlistbySearch($search, $pager->limit);
- $this->data['search'] = $search;
- }elseif(isset($this->params['search']) && !empty($this->params['search']) && isset($this->params['status']) && !empty($this->params['status'])){
- $search = urldecode(trim($this->params['search']));
- $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));
- $pager = new DooPager(Doo::conf()->APP_URL . "m/orderinfo/status/".$this->params['status']."/result/".$search."/page", $totalArchive, 20, 10);
- if (isset($this->params['pindex']))
- $pager->paginate(intval($this->params['pindex']));
- else
- $pager->paginate(1);
- if ($pager->limit != ' -20,20')
- $this->data['orderlist'] = $ktorder->getorderlistbySearch($search, $pager->limit, $this->params['status']);
- $this->data['search'] = $search;
- $this->data['status'] = $this->params['status'];
- }elseif(isset($this->params['status']) && !empty($this->params['status']) && !isset($this->params['search'])){
- $totalArchive = $ktorder->count(array('where' => 'status='.$this->params['status'], 'asArray' => TRUE));
- $pager = new DooPager(Doo::conf()->APP_URL . "m/orderlist/status/".$this->params['status']."/page", $totalArchive, 20, 10);
- if (isset($this->params['pindex']))
- $pager->paginate(intval($this->params['pindex']));
- else
- $pager->paginate(1);
- if ($pager->limit != ' -20,20')
- $this->data['orderlist'] = $ktorder->getorderlist($pager->limit,$this->params['status']);
- $this->data['status'] = $this->params['status'];
- }else{
- $totalArchive = $ktorder->count();
- $pager = new DooPager(Doo::conf()->APP_URL . "m/orderlist/page", $totalArchive, 20, 10);
- if (isset($this->params['pindex']))
- $pager->paginate(intval($this->params['pindex']));
- else
- $pager->paginate(1);
- if ($pager->limit != ' -20,20')
- $this->data['orderlist'] = $ktorder->getorderlist($pager->limit);
- }
- if(isset($this->data['orderlist'])){
- foreach($this->data['orderlist'] as $k => $v){
- $this->data['orderlist'][$k]['createtime'] = date('Y-m-d H:i',$v['createtime']);
- }
- }
- $this->data['pager'] = $pager->output;
- $this->data['order'] = TRUE;
- $this->render ( "admin-orderlist", $this->data, TRUE);
- }
- /**
- * 发票列表
- */
- public function receiptlist(){
- $this->data['order'] = TRUE;
- $this->render ( "admin-receiptlist", $this->data, TRUE);
- }
- public function upload(){
- $this->render('upload', $this->data, TRUE);
- }
- //添加或编辑课程
- public function editClass(){
- if(isset($this->params['classid'])){
- Doo::loadModel('ktclass');
- $ktclass = new Ktclass();
- $this->data['classinfo'] = $ktclass->getRowbyId($this->params['classid']);
- $this->data['classinfo']['stoptime'] = date("Y-m-d",$this->data['classinfo']['stoptime']);
- $this->data['edit'] = true;
- }
- $this->data['jiaoyu'] = TRUE;
- $this->render('admin-editclass', $this->data, true);
- }
- //添加和编辑课程
- public function do_class(){
- if(empty($_POST['classname'])){
- exit('课程名不能为空');
- }
- if(empty($_POST['price'])){
- exit('价格不能为空');
- }
- if(empty($_POST['totalnum'])){
- exit('总课时不能为空');
- }
- if(empty($_POST['classtime'])){
- exit('课程时长不能为空');
- }
- if(empty($_POST['stoptime'])){
- exit('截止日期不能为空');
- }
- if(empty($_POST['desc'])){
- exit('简介不能为空');
- }
- $price = $_POST['price'];
- $name = $_POST['classname'];
- $totalnum = $_POST['totalnum'];
- $classtime = $_POST['classtime'];
- $stop = strtotime($_POST['stoptime']);
- $desc = $_POST['desc'];
- if(!empty($_POST['createtime'])){
- $createTime = $_POST['createtime'];
- }else{
- $createTime = time();
- }
- var_dump($stop);
- $avatar = '';
- if(!empty($_FILES["avatar"]['name'])){
- if ((($_FILES["avatar"]["type"] == "image/gif")
- || ($_FILES["avatar"]["type"] == "image/jpeg")
- || ($_FILES["avatar"]["type"] == "image/pjpeg")
- || ($_FILES["avatar"]["type"] == "image/png"))
- && ($_FILES["avatar"]["size"] < 1048576))
- {
- if ($_FILES["avatar"]["error"] > 0) {
- echo "Return Code: " . $_FILES["avatar"]["error"];
- return false;
- }
- else {
- include (DOO::conf()->SITE_PATH . 'protected/plugin/io.han.php');
- $this->IoHandler = new IoHandler();
- $filedir = $createTime;
- //调用定义物理路径
- $t=DOO::conf()->SITE_PATH."avatar/".$filedir;
- // $t='/opt/www/wenku/report/'.$filedir."/thumb";
- $this->IoHandler->MakeDir($t);
- $upload_dir = $t."/".$createTime.".png";
- $k=move_uploaded_file($_FILES["avatar"]["tmp_name"], $upload_dir);
- if($k) {
- $avatar = 'avatar/'.$createTime.'/'.$createTime.".png";
- }
- }
- }else{
- echo '预览图片文件过大或格式不对';
- return false;
- }
- }elseif(empty($_FILES["avatar"]['name']) && empty($_POST['hadavatar'])){
- exit('请上传预览图');
- }
- Doo::loadModel('ktclass');
- $ktclass = new Ktclass();
- if(isset($_POST['classid']) && !empty($_POST['classid'])){
- $ktclass->classid = $_POST['classid'];
- $ktclass->classname = $name;
- $ktclass->price = $price;
- $ktclass->classnum = $totalnum;
- $ktclass->classtime = $classtime;
- $ktclass->stoptime = $stop;
- $ktclass->description = $desc;
- $ktclass->update();
- }else{
- $ktclass->classname = $name;
- $ktclass->price = $price;
- $ktclass->classnum = $totalnum;
- $ktclass->classtime = $classtime;
- $ktclass->stoptime = $stop;
- $ktclass->description = $desc;
- $ktclass->createtime = $createTime;
- $ktclass->avatar = $avatar;
- $ktclass->ishow = 0;
- $ktclass->insert();
- }
- return '/m/classlist';
- }
- //发布课程
- public function showOnline(){
- if(isset($_POST['classid']) && !empty($_POST['classid'])){
- Doo::loadModel('ktclass');
- $ktclass = new Ktclass();
- $ktclass->classid = $_POST['classid'];
- $ktclass->ishow = 1;
- $result = $ktclass->update();
- if($result){
- echo '1';
- exit();
- }
- }else{
- echo '0';
- exit();
- }
- }
- //课程详情页
- public function classInfo(){
- Doo::loadModel('ktclass');
- Doo::loadModel('classuser');
- Doo::loadModel('kttype');
- $ktclass = new Ktclass();
- $ktype = new Kttype();
- $class_user = new Classuser();
- $this->data['kttype'] = $ktype->getTypebyClassid($this->params['classid']);
- foreach($this->data['kttype'] as $k => $v){
- Doo::loadModel('ktsection');
- $ktsection = new Ktsection();
- $section = $ktsection->getSecbyTypeid($v['typeid']);
- $this->data['kttype'][$k]['section'] = $section;
- foreach($section as $sk => $sv){
- Doo::loadModel('ktvideo');
- $ktvideo = new Ktvideo();
- $video = $ktvideo->getVideobySec($sv['seid']);
- $this->data['kttype'][$k]['section'][$sk]['video'] = $video;
- }
- }
- $this->data['bnum'] = $class_user->getNumbyClassid($this->params['classid']);
- $this->data['classinfo'] = $ktclass->getRowbyId($this->params['classid']);
- $this->data['jiaoyu'] = TRUE;
- $this->render('admin-classinfo', $this->data, true);
- }
- //添加课程里的章
- public function addType(){
- // require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
- // $video = new video ( );
- $typeprefix = $_POST['typeprefix'];
- $typeName = $_POST['typename'];
- $classid = $_POST['classid'];
- if($typeprefix == '' || $typeName == ''){
- exit('请输入章号或章名!');
- }
- // $data = $video->videoTypeCreate($typeName);
- // if($data['code'] == '200'){
- // $video_type_id = $data['ret']['typeId'];
- // }else{
- // exit('网易视频云 - 创建分类失败,请联系管理员');
- // }
- Doo::loadModel('kttype');
- $kttype = new Kttype();
- $kttype->typeprefix = $typeprefix;
- $kttype->typename = $typeName;
- // $kttype->video_typeid = $video_type_id;
- $kttype->createtime = time();
- $kttype->classid = $classid;
- $kttype->insert();
- return '/m/classinfo/'.$classid;
- }
- //编辑章
- public function ExitType(){
- // require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
- // $video = new video ( );
- $typeprefix = $_POST['exprefix'];
- $typeName = $_POST['typename'];
- $classid = $_POST['classid'];
- $typeid = $_POST['typeid'];
- // $wytypeid = $_POST['wytypeid'];
- if($typeprefix == '' || $typeName == ''){
- exit('请输入章号或章名!');
- }
- // $data = $video->videoTypeUpdate($wytypeid, $typeName);
- // if($data['code'] == '200'){
- Doo::loadModel('kttype');
- $kttype = new Kttype();
- $kttype->typeprefix = $typeprefix;
- $kttype->typename = $typeName;
- $kttype->typeid = $typeid;
- $kttype->update();
- // }else{
- // exit('网易视频云 - 修改分类失败,请联系管理员');
- // }
- return '/m/classinfo/'.$classid;
- }
- //删除章
- public function deleteType(){
- // require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
- // $video = new video ( );
- $classid = $this->params['classid'];
- $typeid = $this->params['typeid'];
- Doo::loadModel('kttype');
- $kttype = new Kttype();
- // $wytype = $kttype->getwyidBytypeid($typeid);
- // $data = $video->videoTypeDelete($wytype['video_typeid']);
- // if($data['code'] == '200'){
- $kttype->typeid = $typeid;
- $kttype->delete();
- Doo::loadModel('ktsection');
- $ktsection = new Ktsection();
- $section = $ktsection->getSecbyTypeid($typeid);
- foreach($section as $k => $v){
- $ktsection->seid = $v['seid'];
- $ktsection->delete();
- }
- // }else{
- // exit('网易视频云 - 删除分类失败,请联系管理员');
- // }
- return '/m/classinfo/'.$classid;
- }
- //添加章里的节
- public function addSection(){
- $seprefix = $_POST['seprefix'];
- $seName = $_POST['sename'];
- $typeid = $_POST['typeid'];
- $classid = $_POST['classid'];
- if($seprefix == '' || $seName == ''){
- exit('请输入节号或节名!');
- }
- Doo::loadModel('ktsection');
- $ktsection = new Ktsection();
- $ktsection->seprefix = $seprefix;
- $ktsection->sename = $seName;
- $ktsection->createtime = time();
- $ktsection->typeid = $typeid;
- $ktsection->insert();
- return '/m/classinfo/'.$classid;
- }
- public function exitSection(){
- $seprefix = $_POST['seprefix'];
- $seName = $_POST['sename'];
- $ishow = $_POST['sectionshow'];
- $seid = $_POST['seid'];
- $classid = $_POST['classid'];
- if($seprefix == '' || $seName == ''){
- exit('请输入节号或节名!');
- }
- Doo::loadModel('ktsection');
- $ktsection = new Ktsection();
- $ktsection->seprefix = $seprefix;
- $ktsection->sename = $seName;
- $ktsection->ishow = $ishow;
- $ktsection->seid = $seid;
- $ktsection->update();
- return '/m/classinfo/'.$classid;
- }
- //删除节
- public function deleteSection(){
- $seid = $this->params['seid'];
- $classid = $this->params['classid'];
- Doo::loadModel('ktsection');
- $ktsection = new Ktsection();
- $ktsection->seid = $seid;
- $ktsection->delete();
- return '/m/classinfo/'.$classid;
- }
- //添加视频
- public function addVideo(){
- if(isset($_POST['videomsg']) && !empty($_POST['videomsg'])){
- $videodata = $_POST['videomsg'];
- require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
- $video = new video ( );
- $result = $video->videoGet($videodata['wyvideoid']);
- if($result['code'] == 200){
- Doo::loadModel('ktvideo');
- $ktvideo = new Ktvideo();
- $ktvideo->videoname = basename($videodata['fileName'],".".substr(strrchr($videodata['fileName'], '.'), 1));//不带后缀的视频名
- $ktvideo->objectname = $videodata['objectname'];
- $ktvideo->wy_video_id = $videodata['wyvideoid'];
- $ktvideo->classid = $videodata['classid'];
- $ktvideo->typeid = $videodata['typeid'];
- $ktvideo->seid = $videodata['seid'];
- $ktvideo->type_video_id = 27143;
- $ktvideo->file_time = $result['ret']['duration'];
- $ktvideo->file_ext = $videodata['ext'];
- $ktvideo->file_size = $videodata['size'];
- $ktvideo->isshow = 0;
- $ktvideo->addtime = time();
- $res = $ktvideo->insert();
- }
- }else{
- echo 0;
- exit();
- }
- }
- //修改视频
- public function updateVideo(){
- if(isset($_POST['videoId']) && !empty($_POST['videoId'])){
- $videoid = $_POST['videoId'];
- Doo::loadModel('ktvideo');
- $ktvideo = new Ktvideo();
- $wyvideo = $ktvideo->getvideobyid($videoid);
- if(!empty($wyvideo)){
- $ktvideo->videoid = $_POST['videoId'];
- $ktvideo->videoname = $_POST['videoName'];
- $ktvideo->isshow = $_POST['isshow'];
- $ktvideo->update();
- $section = $ktvideo->getsecbyid($_POST['videoId']);
- $num = $ktvideo->count(array('where' => 'seid='.$section['seid'],'asArray'));
- if($num == 1){
- Doo::loadModel('ktsection');
- $ktsection = new Ktsection();
- if($_POST['isshow'] == 1){
- $ktsection->ishow = 1;
- }else{
- $ktsection->ishow = 0;
- }
- $ktsection->seid = $section['seid'];
- $ktsection->update();
- }
- require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
- $video = new video ( );
- $result = $video->videoEdit($wyvideo['wy_video_id'],$_POST['videoName'].'.'.$wyvideo['file_ext'],$wyvideo['type_video_id']);
- if($result['code'] == 200){
- return '/m/classinfo/'.$_POST['classid'];
- }else{
- return '/m/classinfo/'.$_POST['classid'];
- }
- }else{
- return '/m/classinfo/'.$_POST['classid'];
- }
- }else{
- return '/m/classinfo/'.$_POST['classid'];
- }
- }
- //发布视频
- public function showVideo(){
- $videoid = $this->params['videoid'];
- $classid = $this->params['classid'];
- Doo::loadModel('ktvideo');
- $ktvideo = new Ktvideo();
- $section = $ktvideo->getsecbyid($videoid);
- $num = $ktvideo->count(array('where' => 'seid='.$section['seid'],'asArray'));
- if($num == 1){
- Doo::loadModel('ktsection');
- $ktsection = new Ktsection();
- $ktsection->ishow = 1;
- $ktsection->seid = $section['seid'];
- $ktsection->update();
- }
- $ktvideo->videoid = $videoid;
- $ktvideo->isshow = 1;
- $ktvideo->update();
- return '/m/classinfo/'.$classid;
- }
- //判断视频是否可以发布
- public function isShowVideo(){
- require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
- $video = new video ( );
- $result = $video->videoGet($_GET['video']);
- if($result['code'] == 200) {
- if(empty($result['ret']['shdMp4Url'])){
- echo '0';
- exit;
- }else{
- echo '1';
- exit;
- }
- }else{
- echo '0';
- exit;
- }
- }
- //删除视频
- public function delVideo(){
- $videoid = $this->params['videoid'];
- $classid = $this->params['classid'];
- Doo::loadModel('ktvideo');
- $ktvideo = new Ktvideo();
- $result = $ktvideo->getvideobyid($videoid);
- if(!empty($result)) {
- require_once(Doo::conf()->SITE_PATH . '/protected/class/video.php');
- $video = new video ( );
- $delvideo = $video->videoDetele($result['wy_video_id']);
- $ktvideo->videoid = $videoid;
- $ktvideo->delete();
- }
- return '/m/classinfo/'.$classid;
- }
- //播放转码后视频
- public function playVideo(){
- require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');
- $video = new video ( );
- if(isset($_GET['video'])){
- $result = $video->videoGet($_GET['video']);
- if($result['code'] == 200){
- $play_url = !empty($result['ret']['shdMp4Url']) ? $result['ret']['shdMp4Url'] : '';
- $play_type = substr(strrchr($play_url, '.'), 1);
- if ($play_type == 'mp4'){
- $type = 'video/mp4';
- }else {
- echo json_encode(array( 'code' => 400));
- exit;
- }
- echo json_encode(array( 'code' => 200, 'url' => $play_url, 'type' => $type));
- exit;
- }
- echo json_encode(array( 'code' => 400));
- exit;
- }
- echo json_encode(array( 'code' => 400));
- exit;
- }
- //获取个人的学习进度
- private function getPersonProgress($class,$classuser){
- $totalss = $class['classnum']*$class['classtime']*60; //课程总秒数
- $userss = $classuser['seetime']; //已完成的秒数
- $nodonehh = sprintf('%.2f',($totalss-$userss)/3600); //未完成的小时数
- $donehh = sprintf('%.2f',$classuser['seetime']/3600); //已完成的小时数
- $doneclassnum = intval($userss/($class['classtime']*60)); //已完成的课时数,取整
- if($doneclassnum<10 && $doneclassnum != 0){
- $doneclassnum = '0'.$doneclassnum;
- }
- $progress = sprintf('%.2f',$userss/$totalss) *100; //已完成占总课程的百分比showVideo
- $noprogress = 100-$progress; //未完成占总课程的百分比
- return array('progress' => $progress, 'noprogress' => $noprogress, 'donehh' => $donehh, 'doneclassnum' => $doneclassnum, 'nodonehh' => $nodonehh);
- }
- //获取课程的平均进度
- private function getClassProgress($classid,$totalnum,$bnum){
- if($bnum != 0){
- Doo::loadModel('classuser');
- $classuser = new Classuser();
- $classtrack = $classuser->gettimebyClassid($classid);
- $doness = 0;
- foreach($classtrack as $k => $v){
- $doness += $v['seetime']; //已完成的总秒数
- }
- $donehh = sprintf('%.2f',sprintf('%.2f',$doness/3600)/$bnum); //已完成的平均小时数
- $nodonehh = $totalnum-$donehh; //未完成的小时数
- $progress = sprintf('%.2f',$donehh/$totalnum) *100; //已完成占总课程的百分比
- $noprogress = 100-$progress; //未完成占总课程的百分比
- }else{
- $progress = 0;
- $noprogress = 100;
- $donehh = 0;
- $nodonehh = $totalnum;
- }
- return array('progress' => $progress, 'noprogress' => $noprogress, 'donehh' => $donehh, 'nodonehh' => $nodonehh);
- }
- }
|