| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087 | <?php/** * Created by PhpStorm. * User: ellisran * Date: 2016/9/21 * Time: 10:00 */session_start();class MainController extends DooController {    public $data;    function __construct() {        $this->data['rootUrl'] = Doo::conf()->APP_URL;        if(isset($_COOKIE['uid'])){            $uid = $this->authcode($_COOKIE['uid']);            $username = $this->authcode ( $_COOKIE['user_auth'] );            $this->data['username'] = $username;            $this->data['uid'] = $uid;            //每次操作都更新cookie时间,12小时没操作重新登录            setcookie ( "user_auth", $_COOKIE['user_auth'], time () + 3600 * 12, "/", COOKIE_WEB_SITE );            setcookie ( "uid", $_COOKIE['uid'], time () + 3600 * 12, "/", COOKIE_WEB_SITE );        }        if(isset($_COOKIE['sso_id'])){            require_once (SITE_PATH . '/protected/class/client.php');            $client = new client ( ZHSSO );            $ssoid = $this->authcode($_COOKIE['sso_id']);            $avatar = $client->ps_getavatar ( $ssoid );            $this->data['useravatar']=$avatar[180];            setcookie ( "sso_id", $_COOKIE['sso_id'], time () + 3600 * 12, "/", COOKIE_WEB_SITE );        }else{            $this->data['useravatar']=Doo::conf()->APP_URL . 'global/images/01.png';        }        if(isset($_SESSION['message'])){            $this->data['message'] = $_SESSION['message'];        }    }    public function index() {        Doo::loadModel('ktclass');        Doo::loadModel('classuser');        $ktclass = new Ktclass();        $classuser = new Classuser();        $class = $ktclass->getRowishowbyId(2);        $usernum = $classuser->getNumbyClassid(2);        $this->data['totalnum'] = sprintf("%.2f", $class['classnum']*$class['classtime']/60);        $this->data['usernum'] = $usernum;        $this->data['class'] = $class;        if(isset($this->data['uid'])){            $isbuy = $classuser->gethasbyuserandclass($this->data['uid'],2);            if(!empty($isbuy)){                $this->data['isbuy'] = true;            }        }        $this->render('index', $this->data, TRUE);    }    public function user_exit(){        setcookie('user_auth', '', time () + 3600 * 12, "/", COOKIE_WEB_SITE );        setcookie('uid', '', time () + 3600 * 12, "/", COOKIE_WEB_SITE );        setcookie('sso_id', '', time () + 3600 * 12, "/", COOKIE_WEB_SITE );        return '/';    }    //检测是否已经填入身份证信息和姓名    function checkidcard($id = ''){        if(isset($this->data['uid'])){            $uid = $this->data['uid'];        }elseif($id != ''){            $uid = $id;        }else{            setcookie('user_auth', '', time () + 3600 * 12, "/", COOKIE_WEB_SITE );            setcookie('uid', '', time () + 3600 * 12, "/", COOKIE_WEB_SITE );            setcookie('sso_id', '', time () + 3600 * 12, "/", COOKIE_WEB_SITE );            return 3;        }        Doo::loadModel('user');        $users = new User();        $user = $users->getuserbyId($uid);        if(isset($user['idcard']) && !empty($user['idcard'])){            return 1;        }else{            return 0;        }    }    public function exitId(){        if(isset($this->data['uid'])){            if(isset($_GET['from']) && $_GET['from'] == 'userinfo'){                $this->data['from'] = 'userinfo';            }elseif(isset($_GET['class'])){                $this->data['from'] = $_GET['class'];            }            $this->render('identity', $this->data, TRUE);        }else{            $_SESSION['message'] = 'cookie过期,请重新登录';            return '/';        }    }    public function do_setid(){        if(!isset($this->data['uid'])){            return '/';        }        if(!isset($_POST['name']) || empty($_POST['name'])){            $this->data['message'] = '请输入您的真实姓名';            $this->render('identity',$this->data,TRUE);die;        }        if(!isset($_POST['idcard']) || empty($_POST['idcard'])){            $this->data['message'] = '请输入您的身份证号';            $this->render('identity',$this->data,TRUE);die;        }        if(!$this->validateIDCard($_POST['idcard'])){            $this->data['message'] = '身份证号格式不正确';            $this->render('identity',$this->data,TRUE);die;        }        Doo::loadModel('user');        $users = new User();        $users->realname = trim($_POST['name']);        $users->idcard = trim($_POST['idcard']);        $users->userid = $this->data['uid'];        $users->update();        if(isset($_POST['from']) && $_POST['from'] == 'userinfo'){            return '/userinfo';        }elseif(isset($_POST['from']) && $_POST['from'] == 0){            return '/';        }else{            return '/classinfo/'.$_POST['from'];        }    }    public function login(){        $username = $this->get_args ( "username" );        $password = $this->get_args ( "password" );        if (empty ( $username ) || empty ( $password )) {            $_SESSION['message'] = "请输入正确的参数";            $src_page = $_SERVER['HTTP_REFERER'];            header("location:".$src_page);die;//            return '/';        }        require_once (SITE_PATH . '/protected/class/client.php');        $client = new client ( ZHSSO );        if(filter_var($username, FILTER_VALIDATE_EMAIL)){            $is_login = $client->zhsso_member_login ( $username, $password ,1);        }else if($this->checkMobile($username)) {            $is_login = $client->zhsso_member_login( $username, $password, 2 );        }else{            $is_login = $client->zhsso_member_login ( $username, $password );        }        $is_login = explode ( "\r", $is_login );        if (is_numeric ( $is_login [0] )) {            if ($is_login [0] == USERNAME_ONFINE) {                $_SESSION['message'] = "您输入的帐号或者密码有误";                $src_page = $_SERVER['HTTP_REFERER'];                header("location:".$src_page);die;//                return '/';            } elseif ($is_login [0] == PASSWORD_ERROR){                $_SESSION['message'] = "您输入的帐号或者密码有误";                $src_page = $_SERVER['HTTP_REFERER'];                header("location:".$src_page);die;//                return '/';            }            elseif ($is_login [0] == - 3) {//USER_NOACTION                $_SESSION['message'] =  "用户未激活账号,请前往<a href='http://soo.smartcost.com.cn'>通行账号</a>激活";                return '/';            }            else{                $_SESSION['message'] =  "您输入的帐号或者密码有误";                $src_page = $_SERVER['HTTP_REFERER'];                header("location:".$src_page);die;//                return '/';            }        } elseif (! empty ( $is_login [0] )) {            $ts = json_decode ( $is_login [0], true );            if (empty ( $ts )){                $_SESSION['message'] = "通信异常";                $src_page = $_SERVER['HTTP_REFERER'];                header("location:".$src_page);die;//                return '/';            }            $_SESSION['message'] = '';            Doo::loadModel('user');            $users = new User();            $user = $users->getRowByUsername ( $ts [0] ['username'] );            $ssoid = $this->authcode( $ts[0]['id'], "tr");            $userinfo = $this->authcode ( $ts [0] ['username'], "tr" );            setcookie ( "user_auth", $userinfo, time () + 3600 * 12, "/", COOKIE_WEB_SITE );            setcookie ( "sso_id", $ssoid, time () + 3600 * 12, "/", COOKIE_WEB_SITE );            //同步通行证用户            if (empty ( $user )) {                $users->username = $ts[0]['username'];                $users->useremail = $ts[0]['useremail'];                $users->mobile = $ts[0]['mobile'];                $users->userpasswd = $ts[0]['userpasswd'];                $result = $users->insert();                $userid = $this->authcode ( $result, "tr" );                setcookie ( "uid", $userid, time () + 3600 * 12, "/", COOKIE_WEB_SITE );                $src_page = $_SERVER['HTTP_REFERER'];                header("location:".$src_page);//                return '/setId';            }else{                $users->useremail = $ts[0]['useremail'];                $users->mobile = $ts[0]['mobile'];                $users->userpasswd = $ts[0]['userpasswd'];                $users->userid = $user['userid'];                $users->update();                $userid = $this->authcode ( $user['userid'], "tr" );                setcookie ( "uid", $userid, time () + 3600 * 12, "/", COOKIE_WEB_SITE );                $src_page = $_SERVER['HTTP_REFERER'];                header("location:".$src_page);//                $hadId = $this->checkidcard($user['userid']);////                if($hadId == 0){//                    return '/setId';//                }elseif($hadId == 3){//                    return '/';//                }            }        } else {            $_SESSION['message'] = "通信异常";            $src_page = $_SERVER['HTTP_REFERER'];            header("location:".$src_page);die;//            return '/';        }        $src_page = $_SERVER['HTTP_REFERER'];        header("location:".$src_page);die;//        return '/';    }    //课程列表    public function classlist(){//        $hadId = $this->checkidcard($this->data['uid']);//        if($hadId == 0){//            return '/setId';//        }elseif($hadId == 3){//            return '/';//        }        if(!isset($this->data['uid'])){            return '/';        }        Doo::loadModel('ktclass');        Doo::loadModel('classuser');        $ktclass = new Ktclass();        $classuser = new Classuser();        $classlist = $classuser->getclassbyuserid($this->data['uid']);        $this->data['classlist'] = $classlist;        if(!empty($classlist)){            foreach($classlist as $k => $v){                $class = $ktclass->getOne(array('where' => 'classid='.$v['classid'], 'asArray' => TRUE));                $this->data['classlist'][$k]['classname'] = $class['classname'];                $this->data['classlist'][$k]['avatar'] = $class['avatar'];                $this->data['classlist'][$k]['classnum'] = $class['classnum'];                $this->data['classlist'][$k]['totalnum'] = sprintf("%.2f", $class['classnum']*$class['classtime']/60);                $this->data['classlist'][$k]['usernum'] = $classuser->getNumbyClassid($v['classid']);                $hadbuy = $classuser->gethasbyuserandclass($this->data['uid'],$v['classid']);                $this->data['classlist'][$k]['user_progress'] = $this->getPersonProgress($class,$hadbuy);            }        }        $this->render('user-class', $this->data, TRUE);    }    public function orderlist(){//        $hadId = $this->checkidcard($this->data['uid']);//        if($hadId == 0){//            return '/setId';//        }elseif($hadId == 3){//            return '/';//        }        if(!isset($this->data['uid'])){            return '/';        }        Doo::loadModel('order');        Doo::loadHelper('DooPager');        $order = new Order();        $totalArchive = $order->count(array('where' => 'userid='.$this->data['uid'], 'asArray' => TRUE));        $pager = new DooPager(Doo::conf()->APP_URL . "orderlist/page", $totalArchive, 5, 10);        if (isset($this->params['pindex']))            $pager->paginate(intval($this->params['pindex']));        else            $pager->paginate(1);        if ($pager->limit != ' -5,5')            $orderlist = $order->getorderlistbyuserid($this->data['uid'],$pager->limit);        if(isset($orderlist) && !empty($orderlist)){            $this->data['orderlist'] = $orderlist;            foreach($orderlist as $k => $v){                $this->data['orderlist'][$k]['createtime'] = date('Y-m-d H:i',$v['createtime']);            }        }        $this->data['pager'] = $pager->output;        $this->render('user-order', $this->data, TRUE);    }    //课程详细页    public function classinfo(){//        $hadId = $this->checkidcard($this->data['uid']);//        if($hadId == 0){//            return '/setId';//        }elseif($hadId == 3){//            return '/';//        }        if(isset($this->params['classid'])){            Doo::loadModel('ktclass');            Doo::loadModel('classuser');            $ktclass = new Ktclass();            $classuser = new Classuser();            $class = $ktclass->getRowishowbyId($this->params['classid']);            if(empty($class)){                return '/';            }            $usernum = $classuser->getNumbyClassid($this->params['classid']);            $this->data['totalnum'] = sprintf("%.2f", $class['classnum']*$class['classtime']/60);            $this->data['classinfo'] = $class;            $this->data['usernum'] = $usernum;            Doo::loadModel('ktsection');            Doo::loadModel('kttype');            $ktype = new Kttype();            $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->getVideobySecAndShow($sv['seid']);                    $this->data['kttype'][$k]['section'][$sk]['video'] = $video;                }            }            if(isset($this->data['uid'])){                $hadbuy = $classuser->gethasbyuserandclass($this->data['uid'],$this->params['classid']);                if(!empty($hadbuy)){                    $this->data['isbuy'] = TRUE;                }            }            $this->render('class-info', $this->data, TRUE);        }    }    //跳转到支付宝支付页面    public function paydetail(){        $hadId = $this->checkidcard($this->data['uid']);        if($hadId == 0){            return '/setId?class='.$this->params['classid'];        }elseif($hadId == 3){            return '/';        }        if(isset($this->params['classid'])){            Doo::loadModel('ktclass');            Doo::loadModel('classuser');            $ktclass = new Ktclass();            $classuser = new Classuser();            $class = $ktclass->getRowishowbyId($this->params['classid']);            $usernum = $classuser->getNumbyClassid($this->params['classid']);            $this->data['totalnum'] = sprintf("%.2f", $class['classnum']*$class['classtime']/60);            $this->data['classinfo'] = $class;            $this->data['usernum'] = $usernum;            $hadbuy = $classuser->gethasbyuserandclass($this->data['uid'],$this->params['classid']);            if(!empty($hadbuy)){                $this->data['isbuy'] = TRUE;            }            $this->render('shop-detail', $this->data, TRUE);        }    }    //个人信息页    public function userInfo(){//        $hadId = $this->checkidcard($this->data['uid']);//        if($hadId == 0){//            return '/setId';//        }elseif($hadId == 3){//            return '/';//        }        if(!isset($this->data['uid'])){            return '/';        }        Doo::loadModel('user');        $user = new User();        $this->data['ssoUrl'] = ZHSSO;        $this->data['userinfo'] = $user->getuserbyId($this->data['uid']);        $this->render('user-info',$this->data,TRUE);    }    //修改idcard    public function updateId(){        if(!isset($this->data['uid'])){            return '/';        }        if(!isset($_GET['id']) || empty($_GET['id'])){            $data= '请输入您的身份证号';            echo json_encode(array('code' => 404, 'data' => $data));            exit;        }        if(!$this->validateIDCard($_GET['id'])){            $data = '身份证格式出错,请重新输入';            echo json_encode(array('code' => 404, 'data' => $data));            exit;        }        Doo::loadModel('user');        $user = new User();        $user->userid = $this->data['uid'];        $user->idcard = $_GET['id'];        $user->update();        echo json_encode(array('code' => 200));        exit;    }    //更换头像    public function changeAvatar(){        if(!isset($this->data['uid'])){            return '/';        }        require_once (SITE_PATH . '/protected/class/client.php');        $client = new client ( ZHSSO );        $tuid = $this->authcode($_COOKIE['sso_id']);        $this->data['avatar'] = $client->ps_getavatar ( $tuid );        $this->data ['avatar_flash'] = $client->ps_getavatar_upload_html ( $tuid );        $this->render('user-avatar',$this->data,TRUE);    }    //课程学习页    public function videoInfo(){        Doo::loadModel('ktclass');        Doo::loadModel('classuser');        $ktclass = new Ktclass();        $classuser = new Classuser();        $hadId = $this->checkidcard($this->data['uid']);        if($hadId == 0){            return '/setId';        }elseif($hadId == 3){            return '/';        }        $class = $ktclass->getRowishowbyId($this->params['classid']);        $hadbuy = $classuser->gethasbyuserandclass($this->data['uid'],$this->params['classid']);        if(empty($class)){            return '/';        }        if(empty($hadbuy)){            return '/classinfo/'.$this->params['classid'];        }        $this->data['classinfo'] = $class;        $this->data['totalnum'] = sprintf("%.2f", $class['classnum']*$class['classtime']/60);        Doo::loadModel('ktsection');        Doo::loadModel('kttype');        $ktype = new Kttype();        $type =  $ktype->getTypebyClassid($this->params['classid']);        $this->data['kttype'] =  $type;        $videolist = array();        foreach($type 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->getVideobySecAndShow($sv['seid']);                $this->data['kttype'][$k]['section'][$sk]['video'] = $video;                if(!empty($video)){                    foreach($video as $vk => $vv){                        $videolist[] = $video[$vk];                    }                }            }        }        if(!empty($videolist)){            foreach($videolist as $vk => $vs){                $videolist2[$vk]['videoid'] = $vs['videoid'];                $videolist2[$vk]['wyvideoid'] = $vs['wy_video_id'];                $videolist2[$vk]['videoname'] = $vs['videoname'];            }            $this->data['videolist'] = json_encode($videolist2,TRUE);        }else{            $this->data['videolist'] = '';        }//        var_dump($this->data['videolist']);//        exit;        require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');        $video = new video ( );        if($hadbuy['watch_wyid'] == 0){            $wyvideoid = $this->data['kttype'][0]['section'][0]['video'][0]['wy_video_id'];            $this->data['play_time'] = 0;            $this->data['videoid'] = $this->data['kttype'][0]['section'][0]['video'][0]['videoid'];            $this->data['wyvideoid'] = $this->data['kttype'][0]['section'][0]['video'][0]['wy_video_id'];        }else{            $wyvideoid = $hadbuy['watch_wyid'];            $this->data['play_time'] = $hadbuy['watch_time'];            $this->data['videoid'] = $hadbuy['watch_videoid'];            $this->data['wyvideoid'] = $hadbuy['watch_wyid'];        }        $result = $video->videoGet($wyvideoid);        $type = '';        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';            }        }        if($hadbuy['issuccess'] == 1){            $this->data['successClass'] = 1;        }else{            $this->data['successClass'] = 0;        }        $this->data['user_progress'] = $this->getPersonProgress($class,$hadbuy);        $this->data['play_url'] = isset($play_url) ? $play_url : '';        $this->data['play_type'] = isset($type) ? $type : '';        $this->render('video-play', $this->data, TRUE);    }    //获取个人的学习进度    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;          //已完成占总课程的百分比        $noprogress = 100-$progress;                                //未完成占总课程的百分比        return array('progress' => $progress, 'noprogress' => $noprogress, 'donehh' => $donehh, 'doness' => $userss,'totalss' => $totalss, 'doneclassnum' => $doneclassnum, 'nodonehh' => $nodonehh);    }    //获取视频播放地址    public function playVideo(){        Doo::loadModel('ktclass');        Doo::loadModel('classuser');        $ktclass = new Ktclass();        $classuser = new Classuser();        $hadId = $this->checkidcard($this->data['uid']);        if($hadId == 0){            return '/setId';        }elseif($hadId == 3){            return '/';        }        $class = $ktclass->getRowishowbyId($_POST['classid']);        $hadbuy = $classuser->gethasbyuserandclass($this->data['uid'],$_POST['classid']);        if(empty($class)){            return '/';        }        if(empty($hadbuy)){            return '/classinfo/'.$_POST['classid'];        }        Doo::loadModel('videouser');        $videouser = new Videouser();        $videotime = $_POST['videotime'];        $thisvideo = $_POST['thisvideo'];        $thiswyvideo = $_POST['thiswyvideo'];        $seetime = $_POST['seetime'];        $duration = $_POST['duration'];        if($hadbuy['issuccess'] == 1){            //保存课堂和视频信息到数据库            $classuser->watch_videoid = $thisvideo;            $classuser->watch_wyid = $thiswyvideo;            $classuser->watch_time = $videotime;            $classuser->lasttime = time();            $classuser->id = $hadbuy['id'];            $classuser->update();        }else{            //保存课堂和视频信息到数据库            $classuser->watch_videoid = $thisvideo;            $classuser->watch_wyid = $thiswyvideo;            $classuser->watch_time = $videotime;            $classuser->lasttime = time();            $classuser->seetime = intval($hadbuy['seetime'])+intval($seetime);            $classuser->id = $hadbuy['id'];            $classuser->update();        }        $hadbuy['seetime'] = intval($hadbuy['seetime'])+intval($seetime);        $vuser = $videouser->getvideoMsg($this->data['uid'],$thisvideo);        if(!empty($vuser)){            $videouser->id = $vuser['id'];            $videouser->file_time = $duration;            $videouser->seetime = $videotime;            $videouser->last_time = time();            $videouser->update();        }else{            $videouser->userid = $this->data['uid'];            $videouser->videoid = $thisvideo;            $videouser->wyvideoid = $thiswyvideo;            $videouser->file_time = $duration;            $videouser->seetime = $videotime;            $videouser->last_time = time();            $videouser->insert();        }        $watchtime = $videouser->gettimebywyvideo($this->data['uid'],$_POST['video']);        $user_progress = $this->getPersonProgress($class,$hadbuy);        require_once (Doo::conf()->SITE_PATH . '/protected/class/video.php');        $video = new video ( );        if(isset($_POST['video'])){            $result = $video->videoGet($_POST['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, 'seetime' => $watchtime, 'user_progress' => $user_progress));                exit;            }            echo json_encode(array( 'code' => 400));            exit;        }        echo json_encode(array( 'code' => 400));        exit;    }    //保存视频信息    public function saveClassAndVideo(){        Doo::loadModel('ktclass');        Doo::loadModel('classuser');        $ktclass = new Ktclass();        $classuser = new Classuser();        $hadId = $this->checkidcard($this->data['uid']);        if($hadId == 0){            return '/setId';        }elseif($hadId == 3){            return '/';        }        $class = $ktclass->getRowishowbyId($_POST['classid']);        $hadbuy = $classuser->gethasbyuserandclass($this->data['uid'],$_POST['classid']);        if(empty($class)){            return '/';        }        if(empty($hadbuy)){            return '/classinfo/'.$_POST['classid'];        }        Doo::loadModel('videouser');        $videouser = new Videouser();        $videotime = $_POST['videotime'];        $videoid = $_POST['video'];        $wyvideoid = $_POST['wyvideo'];        $seetime = $_POST['seetime'];        $duration = $_POST['duration'];        //判断课程是否已完成,已完成则不再上传课程时间        if($hadbuy['issuccess'] == 0 && intval($hadbuy['seetime'])+intval($seetime) >= $class['classnum']*$class['classtime']*60){            $classuser->issuccess = 1;            $classuser->watch_videoid = $videoid;            $classuser->watch_wyid = $wyvideoid;            $classuser->watch_time = $videotime;            $classuser->lasttime = time();            $classuser->seetime = intval($hadbuy['seetime'])+intval($seetime);            $classuser->id = $hadbuy['id'];            $classuser->update();        }elseif($hadbuy['issuccess'] == 1){            $classuser->watch_videoid = $videoid;            $classuser->watch_wyid = $wyvideoid;            $classuser->watch_time = $videotime;            $classuser->lasttime = time();            $classuser->id = $hadbuy['id'];            $classuser->update();        }else{            //保存课堂和视频信息到数据库            $classuser->watch_videoid = $videoid;            $classuser->watch_wyid = $wyvideoid;            $classuser->watch_time = $videotime;            $classuser->lasttime = time();            $classuser->seetime = intval($hadbuy['seetime'])+intval($seetime);            $classuser->id = $hadbuy['id'];            $classuser->update();        }        $hadbuy['seetime'] = intval($hadbuy['seetime'])+intval($seetime);        $vuser = $videouser->getvideoMsg($this->data['uid'],$videoid);        if(!empty($vuser)){            $videouser->id = $vuser['id'];            $videouser->file_time = $duration;            $videouser->seetime = $videotime;            $videouser->last_time = time();            $videouser->update();        }else{            $videouser->userid = $this->data['uid'];            $videouser->videoid = $videoid;            $videouser->wyvideoid = $wyvideoid;            $videouser->file_time = $duration;            $videouser->seetime = $videotime;            $videouser->last_time = time();            $videouser->insert();        }        $user_progress = $this->getPersonProgress($class,$hadbuy);        echo json_encode(array('user_progress' => $user_progress));        exit;    }    public function alipay(){        Doo::loadModel('ktclass');        Doo::loadModel('classuser');        $ktclass = new Ktclass();        $classuser = new Classuser();        $hadId = $this->checkidcard($this->data['uid']);        if($hadId == 0){            return '/setId';        }elseif($hadId == 3){            return '/';        }        if(isset($this->params['classid'])){            $class = $ktclass->getRowishowbyId($this->params['classid']);            $hadbuy = $classuser->gethasbyuserandclass($this->data['uid'],$this->params['classid']);            if(!empty($class) && empty($hadbuy)){                Doo::loadModel('user');                $users = new User();                $user = $users->getuserbyId($this->data['uid']);                require_once(Doo::conf()->SITE_PATH."protected/class/alipay/alipay.config.php");                require_once(Doo::conf()->SITE_PATH."protected/class/alipay/lib/alipay_submit.class.php");                $alipaySubmit = new AlipaySubmit($alipay_config);                $payment_type = "1";                $notify_url = Doo::conf()->APP_URL."api/smartcost/sso/notify_url";                $return_url = Doo::conf()->APP_URL."api/smartcost/sso/return_url";                //商户订单号                $sn=$this->create_sn();                $out_trade_no = $sn;                $subject = $class['classname'].'费用支付';                $extra_common_param=''; //用户自定义回传参数                //付款金额                $p_amount=trim($class['price']);                $total_fee = $p_amount;                $body = '';                $show_url = '';                //防钓鱼时间戳                $anti_phishing_key = $alipaySubmit->query_timestamp();                $exter_invoke_ip = $this->clientIP();                //构造要请求的参数数组,无需改动                $parameter = array(                    "service" => "create_direct_pay_by_user",                    "partner" => trim($alipay_config['partner']),                    "seller_email" => trim($alipay_config['seller_email']),                    "payment_type"	=> $payment_type,                    "notify_url"	=> $notify_url,                    "return_url"	=> $return_url,                    "out_trade_no"	=> $out_trade_no,                    "subject"	=> $subject,                    "total_fee"	=> $total_fee,                    "body"	=> $body,                    "show_url"	=> $show_url,                    "anti_phishing_key"	=> $anti_phishing_key,                    "exter_invoke_ip"	=> $exter_invoke_ip,                    "_input_charset"	=> trim(strtolower($alipay_config['input_charset'])),                    "extra_common_param"=> $extra_common_param                );                //建立请求                $html_text = $alipaySubmit->buildRequestForm($parameter,"get", "加载中");                // 生成订单                Doo::loadModel('order');                $order = new Order();                $array = array('trade_sn' => $sn,                    'userid' => $this->data['uid'],                    'username' => $this->data['username'],                    'useremail' => $user['useremail'],                    'mobile' => $user['mobile'],                    'price' => $p_amount,                    'createtime' => time(),                    'classid' => $this->params['classid'],                    'classname' => $class['classname'],                    'ip' => $this->clientIP(),                    'status' => 2                );                $order->_insertAttributes('order', $array);                header("Content-type: text/html; charset=utf-8");                echo $html_text;            }else{                return '/classinfo/'.$this->params['classid'];            }        }    }    function returnAlipay(){        $hadId = $this->checkidcard($this->data['uid']);        if($hadId == 0){            return '/setId';        }elseif($hadId == 3){            return '/';        }        require_once(Doo::conf()->SITE_PATH."protected/class/alipay/alipay.config.php");        require_once(Doo::conf()->SITE_PATH."protected/class/alipay/lib/alipay_notify.class.php");        $alipayNotify = new AlipayNotify($alipay_config);        $verify_result = $alipayNotify->verifyReturn();        if($verify_result) {            $v_oid = $_GET['out_trade_no'];	//商户订单号            $trade_no = $_GET['trade_no'];			//支付宝交易号            $trade_status = $_GET['trade_status'];	//交易状态            $v_amount=$_GET['total_fee'];			//交易金额            if($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') {                $order = Doo::loadModel('order', TRUE);                $callbackData = $order->getRowsBytrade_id($v_oid);                if ($callbackData['status'] == 2) {                    if ($callbackData['price'] == $v_amount) {                        $order->trade_sn = $v_oid;                        $comment = $order->find(array('limit' => 1, 'select' => 'id', 'where' => 'trade_sn='.$v_oid, 'asArray' => TRUE));                        $order->id = $comment['id'];                        $order->paytime = time();                        $order->status = 1;                        $succvalue = $order->update();                        if ($succvalue) {                            Doo::loadModel('classuser');                            $classuser = new Classuser();                            $classuser->userid = $callbackData['userid'];                            $classuser->classid = $callbackData['classid'];                            $classuser->price = $callbackData['price'];                            $classuser->issuccess = 0;                            $result = $classuser->insert();                            if ($result) {                                $this->data['msg'] = '支付完成';                                header('refresh:3;url=/classinfo/'.$callbackData['classid']);                            }                        }                    }                } else {                    $this->data['msg'] = '已支付完毕,操作无效';                    header('refresh:3;url=/');                }            }        }else {            $this->data['msg'] = '支付故障';            header('refresh:3;url=/');        }        $this->render('pay_msg', $this->data, TRUE);    }    function notifyAlipay(){        require_once(Doo::conf()->SITE_PATH."protected/class/alipay/alipay.config.php");        require_once(Doo::conf()->SITE_PATH."protected/class/alipay/lib/alipay_notify.class.php");        $alipayNotify = new AlipayNotify($alipay_config);        $verify_result = $alipayNotify->verifyNotify();        if($verify_result) {            $v_oid = $_POST['out_trade_no'];	//商户订单号            $trade_no = $_POST['trade_no'];			//支付宝交易号            $trade_status = $_POST['trade_status'];	//交易状态            $v_amount=$_POST['total_fee'];			//交易金额            if($_POST['trade_status'] == 'TRADE_FINISHED' || $_POST['trade_status'] == 'TRADE_SUCCESS') {                $order = Doo::loadModel('order', TRUE);                $callbackData = $order->getRowsBytrade_id($v_oid);                if ($callbackData['status'] == 2) {                    if ($callbackData['price'] == $v_amount) {                        $order->trade_sn = $v_oid;                        $comment = $order->find(array('limit' => 1, 'select' => 'id', 'where' => 'trade_sn='.$v_oid, 'asArray' => TRUE));                        $order->id = $comment['id'];                        $order->paytime = time();                        $order->status = 1;                        $succvalue = $order->update();                        if ($succvalue) {                            Doo::loadModel('classuser');                            $classuser = new Classuser();                            $classuser->userid = $callbackData['userid'];                            $classuser->classid = $callbackData['classid'];                            $classuser->price = $callbackData['price'];                            $classuser->issuccess = 0;                            $result = $classuser->insert();                            if($result) {                                echo "success";                                die;                            }                        }                    }                }            }            echo "success";        }else {            echo "fail";        }    }    /**     * 生成流水号     */    function create_sn() {        mt_srand((double) microtime() * 1000000);        return date("YmdHis") . str_pad(mt_rand(1, 99999), 5, "0", STR_PAD_LEFT);    }    // 检测手机格式    function checkMobile($mobile) {        if(preg_match("/^1[34578]{1}\d{9}$/",$mobile)){            return TRUE;        } else {            return FALSE;        }    }    //验证身份证是否有效    function validateIDCard($IDCard) {        if (strlen($IDCard) == 18) {            return $this->check18IDCard($IDCard);        } elseif ((strlen($IDCard) == 15)) {            $IDCard = $this->convertIDCard15to18($IDCard);            return $this->check18IDCard($IDCard);        } else {            return false;        }    }//计算身份证的最后一位验证码,根据国家标准GB 11643-1999    function calcIDCardCode($IDCardBody) {        if (strlen($IDCardBody) != 17) {            return false;        }        //加权因子        $factor = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);        //校验码对应值        $code = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');        $checksum = 0;        for ($i = 0; $i < strlen($IDCardBody); $i++) {            $checksum += substr($IDCardBody, $i, 1) * $factor[$i];        }        return $code[$checksum % 11];    }// 将15位身份证升级到18位    function convertIDCard15to18($IDCard) {        if (strlen($IDCard) != 15) {            return false;        } else {            // 如果身份证顺序码是996 997 998 999,这些是为百岁以上老人的特殊编码            if (array_search(substr($IDCard, 12, 3), array('996', '997', '998', '999')) !== false) {                $IDCard = substr($IDCard, 0, 6) . '18' . substr($IDCard, 6, 9);            } else {                $IDCard = substr($IDCard, 0, 6) . '19' . substr($IDCard, 6, 9);            }        }        $IDCard = $IDCard . $this->calcIDCardCode($IDCard);        return $IDCard;    }// 18位身份证校验码有效性检查    function check18IDCard($IDCard) {        if (strlen($IDCard) != 18) {            return false;        }        $IDCardBody = substr($IDCard, 0, 17); //身份证主体        $IDCardCode = strtoupper(substr($IDCard, 17, 1)); //身份证最后一位的验证码        if ($this->calcIDCardCode($IDCardBody) != $IDCardCode) {            return false;        } else {            return true;        }    }    /**     * 获取get或者POST值     * @param string $name 属性名称     * @return fixed 值     */    function get_args($name) {        if (isset ( $_GET [$name] )) {            if (is_array ( $_GET [$name] ))                return $_GET [$name];            else                return addslashes ( $_GET [$name] );        } elseif (isset ( $_POST [$name] )) {            if (is_array ( $_POST [$name] ))                return $_POST [$name];            else                return addslashes ( $_POST [$name] );        } else {            return false;        }    }    function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {        $ckey_length = 4;        if (! $key) {            $key = "ZHKT";        }        $key = md5 ( $key );        $keya = md5 ( substr ( $key, 0, 16 ) );        $keyb = md5 ( substr ( $key, 16, 16 ) );        $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';        $cryptkey = $keya . md5 ( $keya . $keyc );        $key_length = strlen ( $cryptkey );        $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;        $string_length = strlen ( $string );        $result = '';        $box = range ( 0, 255 );        $rndkey = array ();        for($i = 0; $i <= 255; $i ++) {            $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );        }        for($j = $i = 0; $i < 256; $i ++) {            $j = ($j + $box [$i] + $rndkey [$i]) % 256;            $tmp = $box [$i];            $box [$i] = $box [$j];            $box [$j] = $tmp;        }        for($a = $j = $i = 0; $i < $string_length; $i ++) {            $a = ($a + 1) % 256;            $j = ($j + $box [$a]) % 256;            $tmp = $box [$a];            $box [$a] = $box [$j];            $box [$j] = $tmp;            $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );        }        if ($operation == 'DECODE') {            if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {                return substr ( $result, 26 );            } else {                return '';            }        } else {            return $keyc . str_replace ( '=', '', base64_encode ( $result ) );        }    }}
 |