123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547 |
- <?php
- ini_set('display_errors', 1);
- Doo::loadClass('auth');
- Doo::loadClass('attfile');
- Doo::loadClass('profile');
- Doo::loadClass('project');
- Doo::loadClass('contractact');
- Doo::loadClass('actmeasure');
- Doo::loadClass('numofperact');
- Doo::loadClass('user');
- Doo::loadClass('PasswordHash');
- Doo::loadClass('sms');
- Doo::loadModelAt('aconfig', 'admin');
- Doo::loadClass('measureauditact');
- /* * proDetail
- * MainController
- * Feel free to delete the methods and replace them with your own code.
- *
- * @author darkredz
- */
- class UserController extends DooController
- {
- private $data, $auth, $attfile, $profile, $project, $contractact, $actmeasure, $numofperact, $user, $ph, $sms, $aconfig;
- public function beforeRun($resource, $action)
- {
- // $uGroups = $this->profile->getProWithUid($this->auth->getUid());
- // $falg = Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
- // if (!$falg)
- // return Doo::acl()->defaultFailedRoute;
- if ($this->auth->getUid()) {
- $uGroups = $this->profile->getProWithUid($this->auth->getUid());
- $falg = Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
- if (!$falg)
- return Doo::acl()->defaultFailedRoute;
- } else {
- return Doo::acl()->defaultFailedRoute;
- }
- }
- public function __construct()
- {
- $this->data['numofchecking'] = null;
- $this->auth = new Auth();
- $this->attfile = new attFile();
- $this->profile = new Profile();
- $this->project = new Project();
- $this->contractact = new Contractact();
- $this->actmeasure = new actMeasure();
- $this->numofperact = new NumofperAct();
- $this->user = new User();
- $this->ph = new PasswordHash(8, FALSE);
- $this->sms = new Sms(Doo::conf()->SMS_URL, Doo::conf()->SMS_AUTHKEY);
- $this->aconfig = new AConfig();
- $this->measureauditact = new MeasureauditAct();
- $this->data['rootUrl'] = Doo::conf()->APP_URL;
- $this->data['currChannle'] = 'p';
- $this->data['user'] = $this->profile->getProWithUid($this->auth->getUid());
- $mpidArray = $this->measureauditact->getAuditProject2($this->auth->getUid());
- if (isset($mpidArray[0]['pid'])) {
- foreach ($mpidArray as $key => $value) {
- // 审批操作按照时间排序多标段
- $this->data['numofchecking'] += $this->measureauditact->getCountMyChecking($value['pid'], $this->auth->getUid());
- }
- }
- if ($this->data['numofchecking'] == 0) {
- $this->data['numofchecking'] = null;
- }
- }
- /**
- *
- * @return type
- */
- public function index()
- {
- $this->data['uprofile'] = $this->profile->getProWithUid($this->auth->getUid());
- $this->data['uprofile']['email'] = $this->auth->getUemail();
- if (isset($_POST['name']) && isset($_POST['company']) && isset($_POST['jobs']) && isset($_POST['phone'])) {
- $this->profile->upProfile($this->auth->getUid(), $_POST);
- return DOO::conf()->APP_URL . 'user/profile';
- }
- $this->render('edit-profile', $this->data, TRUE);
- }
- public function avatar()
- {
- // TODO:加入目录可否写入判断
- if (count($_FILES) == 3) {
- $result = array();
- $result['success'] = false;
- $successNum = 0;
- $avatarNumber = 1;
- $i = 0;
- $msg = '';
- $dir = 'global/avatar';
- while (list($key, $val) = each($_FILES)) {
- if ($_FILES[$key]['error'] > 0) {
- $msg .= $_FILES[$key]['error'];
- } else {
- $fileName = date("YmdHis") . '_' . floor(microtime() * 1000) . '_' . self::createRandomCode(8);
- if ($key == '__source') {
- $initParams = $_POST["__initParams"];
- $virtualPath = "$dir/php_source_$fileName.jpg";
- $result['sourceUrl'] = '/' . $virtualPath . $initParams;
- move_uploaded_file($_FILES[$key]["tmp_name"], Doo::conf()->SITE_PATH . $virtualPath);
- $successNum++;
- } else if (strpos($key, '__avatar') === 0) {
- $virtualPath = "$dir/php_avatar" . $avatarNumber . "_$fileName.jpg";
- $result['avatarUrls'][$i] = $virtualPath;
- if ($i == 2) {
- $this->profile->setAvatar($this->auth->getUid(), $result['avatarUrls'][$i]);
- }
- move_uploaded_file($_FILES[$key]["tmp_name"], $virtualPath);
- $successNum++;
- $i++;
- }
- }
- }
- $result['msg'] = $msg;
- if ($successNum > 0) {
- $result['success'] = true;
- }
- print json_encode($result);
- die;
- }
- $this->render('edit-profile-avtra', $this->data, TRUE);
- }
- /* * ************************************************************
- * 生成指定长度的随机码。
- * @param int $length 随机码的长度。
- * @access public
- * ************************************************************ */
- function createRandomCode($length)
- {
- $randomCode = "";
- $randomChars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- for ($i = 0; $i < $length; $i++) {
- $randomCode .= $randomChars{mt_rand(0, 35)};
- }
- return $randomCode;
- }
- public function proSection()
- {
- /**
- * 计量期数
- * 完成进度
- *
- */
- $this->getFav();
- $contractArray = $this->contractact->getRowByPid($this->params['pid']); // 获取合同段
- $htmlstr = NULL;
- foreach ($contractArray as $k => $v) {
- $retval = $this->actmeasure->getAllbyStid($v['stid']); // 获取标段
- $bdhtmlstr = NULL;
- $biaoduantotalmoney = 0;
- $currTotal = 0;
- $progress = $otherprogress = '0%';
- $currTotal = $this->numofperact->getCountTotalSTID($v['stid']);
- //
- foreach ($retval as $key => $value) {
- $snTotalProgress = $currTotalProgress = $lessTotalProgress = '0%';
- $numCount = $this->numofperact->getCountTotalnum($value['pmid']);
- $totalplus = $this->numofperact->getCountTotalplus($value['pmid']);
- $snTotal = $this->numofperact->getStopNow($value['pmid']); //截止目前
- $currcomTotal = $this->numofperact->getCurrTotal($value['pmid']); //截止目前
- if ($numCount > 0) {
- $nTotalProgress = number_format($snTotal['sntotal'], 2, '.', ',');
- $ncurrTotalProgress = number_format($currcomTotal['currtotal'], 2, '.', ',');
- $nlessTotalProgress = number_format($totalplus['totalplus'] - $currcomTotal['currtotal'] - $snTotal['sntotal'], 2, '.', ',');
- $snTotalProgress = round(($snTotal['sntotal'] / $totalplus['totalplus']) * 100) . '%';
- $currTotalProgress = round(($currcomTotal['currtotal'] / $totalplus['totalplus']) * 100) . '%';
- $lessTotalProgress = round((($totalplus['totalplus'] - $currcomTotal['currtotal'] - $snTotal['sntotal']) / $totalplus['totalplus']) * 100) . '%';
- }
- $biaoduantotalmoney += $value['contracttotal'];
- $totalmoney = number_format($value['contracttotal'], 2, '.', ',');
- $bdhtmlstr .= '
- <thead>
- <tr><th class="taC" width="225">标段名</th><th class="taC" width="140">计量期数</th><th width="115" class="taC">总价</th><th class="taC" width="">截止本期累计完成/本期完成/未完成</th></tr></thead>
- <tbody>
- <tr>
- <td><a href="/project/1/section/' . $value['pmid'] . '/detail">' . $value['pmname'] . '</a></td>
- <td class="">共 ' . $numCount . ' 期(本期 <span class="colOrange">审批中</span>)</td>
- <td class="taR">¥' . $totalmoney . '</td>
- <td>
- <div class="progress">
- <div class="bar bar-success" style="width: ' . $snTotalProgress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="截止本期累计完成:¥' . $nTotalProgress . '">' . $snTotalProgress . '</div>
- <div class="bar" style="width:' . $currTotalProgress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="本期完成:¥' . $ncurrTotalProgress . '">' . $currTotalProgress . '</div>
- <div class="bar bar-gary" style="width:' . $lessTotalProgress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="未完成:¥' . $nlessTotalProgress . '">' . $lessTotalProgress . '</div>
- </div>
- </td>
- </tr>';
- }
- if ($biaoduantotalmoney > 0 && ($currTotal['totalplus'] > 0)) {
- $nprogress = number_format($currTotal['totalplus'], 2, '.', ',');
- $notherprogress = number_format($biaoduantotalmoney - $currTotal['totalplus'], 2, '.', ',');
- $progress = round(($currTotal['totalplus'] / $biaoduantotalmoney) * 100) . '%';
- $otherprogress = round((($biaoduantotalmoney - $currTotal['totalplus']) / $biaoduantotalmoney) * 100) . '%';
- $biaoduantotalmoney = number_format($biaoduantotalmoney, 2, '.', ',');
- }
- $htmlstr .= '<div class="project">
- <div class="proSection">
- <table class="table">
- <thead>
- <tr>
- <td width="150"><span aria-hidden="true" data-icon="u"></span> ' . $v['stname'] . '(' . $v['stkey'] . ') <a href="#secoption" data-toggle="modal" title="编辑/查看KEY"><span data-icon="S" aria-hidden="true" value="' . $v['stid'] . '" class="closePanel"></span></a></td>
- <td width="90">总价:</td><td width="165">¥<b style="font-size:16px">' . $biaoduantotalmoney . '</b></td>
- <td width="60">完成进度:</td><td><div class="progress">
- <div class="bar bar-success" style="width:' . $progress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="累计完成:¥' . $nprogress . '">' . $progress . '</div>
- <div class="bar bar-danger" style="width:' . $otherprogress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="未完成:¥' . $notherprogress . '">' . $otherprogress . '</div>
- </div></td>
- </tr>
- </thead>
- </table>
- <table class="table table-striped table-hover">
- ' . $bdhtmlstr . '
- </tbody>
- </table>
- </div>
- </div>';
- }
- $this->data['htmlstr'] = $htmlstr;
- if (isset($_POST['secname']) && $_POST['secname']) {
- $this->contractact->insertContract($this->params['pid'], $this->auth->getUid(), $_POST['secname']);
- return Doo::conf()->APP_URL . 'project/' . $this->params['pid'] . '/section';
- }
- $this->data['pid'] = $this->params['pid'];
- $this->render('w-project-section', $this->data, TRUE);
- }
- /**
- *
- * @return type
- */
- public function sms()
- {
- if (isset($_POST['mobile']) && isset($_POST['verifycode'])) {
- $vmArray = $this->auth->getVerifyMobile();
- if (isset($vmArray) && $vmArray) {
- if (md5($_POST['mobile'] . $_POST['verifycode']) == md5($vmArray['mobile'] . $vmArray['code'])) {
- $this->profile->updateMobile($this->auth->getUid(), $vmArray['mobile']);
- return Doo::conf()->APP_URL . 'user/profile/sms';
- }
- }
- }
- $this->data['uprofile'] = $this->profile->getProWithUid($this->auth->getUid());
- $this->data['smsNoticeSwitch'] = $this->aconfig->getOne(array('select' => 'smsswitch', 'asArray' => TRUE))['smsswitch'];
- $this->render('edit-profile-sms', $this->data, TRUE);
- }
- /**
- *
- * @return type
- */
- public function smsEdit()
- {
- if (isset($_POST['mobile']) && isset($_POST['verifycode'])) {
- $vmArray = $this->auth->getVerifyMobile();
- if (isset($vmArray) && $vmArray) {
- if (md5($_POST['mobile'] . $_POST['verifycode']) == md5($vmArray['mobile'] . $vmArray['code'])) {
- $this->profile->updateMobile($this->auth->getUid(), $vmArray['mobile']);
- return Doo::conf()->APP_URL . 'user/profile/sms/edit';
- }
- }
- }
- $this->data['uprofile'] = $this->profile->getProWithUid($this->auth->getUid());
- $this->render('edit-profile-sms-edit', $this->data, TRUE);
- }
- /**
- *
- * @return type
- */
- public function checkMobile()
- {
- // $this->data['uprofile']['email'] = $this->auth->getUemail();
- // if (isset($_POST['name']) && isset($_POST['company']) && isset($_POST['jobs']) && isset($_POST['phone']) && isset($_POST['mobile'])) {
- // $this->profile->upProfile($this->auth->getUid(), $_POST);
- // return DOO::conf()->APP_URL . 'user/profile';
- // }
- die(json_encode(array('mobile' => (int)$this->profile->checkMobile($_POST['mobile']))));
- }
- /**
- *
- * @return type
- */
- public function mobileVerify()
- {
- // $this->data['uprofile']['email'] = $this->auth->getUemail();
- // if (isset($_POST['name']) && isset($_POST['company']) && isset($_POST['jobs']) && isset($_POST['phone']) && isset($_POST['mobile'])) {
- // $this->profile->upProfile($this->auth->getUid(), $_POST);
- // return DOO::conf()->APP_URL . 'user/profile';
- // }
- die(json_encode(array('mobile' => (int)$this->profile->checkMobile($_POST['mobile']))));
- }
- /**
- *
- * @return type
- */
- public function smsSend()
- {
- $randNum = rand(1000, 9999);
- $this->auth->setVerifyMobile(array('mobile' => $_POST['mobile'], 'code' => $randNum));
- $res = $this->sms->sendSms($_POST['mobile'], Doo::conf()->SMS_TIPS['AUDIT_NOTICE'] . $randNum . Doo::conf()->SMS_TIPS['END_MSG']);
- die(json_encode(array('verify' => $res)));
- }
- Function fNumber($number)
- {
- if ($number == '')
- Return "-";
- $nlen = strlen($number);
- while ($nlen > 3) {
- $fNumber = "," . substr($number, $nlen - 3, 3);
- $number = substr($number, 0, -3);
- $nlen = strlen($number);
- }
- if ($nlen <= 3) {
- $fNumber = $number . $fNumber;
- }
- Return $fNumber;
- }
- private function getFav()
- {
- $proArray = $this->project->getAll();
- $this->data['othrPro'] = [];
- foreach ($proArray as $key => $value) {
- if ($value['pid'] == $this->params['pid']) {
- $this->data['currProName'] = $value['pname'];
- $this->data['currProID'] = $value['pid'];
- } else {
- $this->data['othrPro'][] = $proArray[$key];
- }
- }
- }
- public function proSectionMeasure()
- {
- //此处未做更改,JSON文件已经固定名称
- $jsonpath = pathinfo($this->attfile->getMaxRow()['filepath']);
- if (isset($jsonpath['dirname'])) {
- $extPathdir = Doo::conf()->SITE_PATH . $jsonpath['dirname'] . '/' . $jsonpath['filename'];
- if ($handle = opendir($extPathdir)) {
- while (false !== ($file = readdir($handle))) {
- $filename = NULL;
- $filename = pathinfo($file);
- if ($filename['extension'] == 'json')
- $proArray = json_decode(file_get_contents($extPathdir . '/' . $file), TRUE, JSON_UNESCAPED_UNICODE);
- }
- closedir($handle);
- }
- $this->data['proArray'] = $proArray['Bills'];
- } else {
- $this->data['proArray'] = [];
- }
- $this->data['mpid'] = $this->params['mpid'];
- $this->data['pid'] = $this->params['pid'];
- $this->render('w-project-section-measure', $this->data, TRUE);
- }
- public function substr_replace_cn($string, $repalce = '*', $start = 0, $len = 0)
- {
- $count = mb_strlen($string, 'UTF-8'); //此处传入编码,建议使用utf-8。此处编码要与下面mb_substr()所使用的一致
- if (!$count) {
- return $string;
- }
- if ($len == 0) {
- $end = $count; //传入0则替换到最后
- } else {
- $end = $start + $len; //传入指定长度则为开始长度+指定长度
- }
- $i = 0;
- $returnString = '';
- while ($i < $count) { //循环该字符串
- $tmpString = mb_substr($string, $i, 1, 'UTF-8'); // 与mb_strlen编码一致
- if ($start <= $i && $i < $end) {
- $returnString .= $repalce;
- } else {
- $returnString .= $tmpString;
- }
- $i++;
- }
- return $returnString;
- }
- function unicode_encode($name)
- {//to Unicode
- $name = iconv('UTF-8', 'UCS-2', $name);
- $len = strlen($name);
- $str = '';
- for ($i = 0; $i < $len - 1; $i = $i + 2) {
- $c = $name[$i];
- $c2 = $name[$i + 1];
- if (ord($c) > 0) {// 两个字节的字
- $str .= '\\' . base_convert(ord($c), 10, 16) . base_convert(ord($c2), 10, 16);
- } else {
- $str .= $c2;
- }
- }
- $str = strtoupper($str);
- return $str;
- }
- function unicode_decode($name)
- {//Unicode to
- $pattern = '/([\w]+)|(\\\u([\w]{4}))/i';
- preg_match_all($pattern, $name, $matches);
- if (!empty($matches)) {
- $name = '';
- for ($j = 0; $j < count($matches[0]); $j++) {
- $str = $matches[0][$j];
- if (strpos($str, '\\u') === 0) {
- $code = base_convert(substr($str, 2, 2), 16, 10);
- $code2 = base_convert(substr($str, 4), 16, 10);
- $c = chr($code) . chr($code2);
- $c = iconv('UCS-2', 'UTF-8', $c);
- $name .= $c;
- } else {
- $name .= $str;
- }
- }
- }
- return $name;
- }
- public function proDetail()
- {
- // 面包屑导航项目
- $this->data['currproArray'] = $this->data['allproArray'] = NULL;
- $allproArray = $this->project->getAll();
- foreach ($allproArray as $kk => $vv) {
- if ($vv['pid'] == $this->params['pid']) {
- $this->data['currproArray'] = $vv;
- } else {
- $this->data['allproArray'][] = $vv;
- }
- }
- // 面包屑导航合同
- $conArray = $this->contractact->getAll();
- $measureArray = $this->actmeasure->getRowByPmid($this->params['pmid']);
- if (isset($measureArray['stid'])) {
- foreach ($conArray as $kkk => $vvv) {
- if ($vvv['stid'] == $measureArray['stid']) {
- $this->data['currconArray'] = $vvv;
- } else {
- $this->data['allconArray'][] = $vvv;
- }
- }
- } else {
- $this->data['currconArray'] = $this->data['allconArray'] = NULL;
- }
- // 面包屑导航标段
- $this->data['curractmeasureArray'] = NULL;
- $this->data['allactmeasureArray'] = [];
- $actmeasureArray = $this->actmeasure->getAll();
- foreach ($actmeasureArray as $kkkk => $vvvv) {
- if ($vvvv['stid'] == $measureArray['stid']) {
- if (($vvvv['pmid'] == $this->params['pmid'])) {
- $this->data['curractmeasureArray'] = $vvvv;
- } else {
- $this->data['allactmeasureArray'][] = $vvvv;
- }
- }
- }
- // 图标
- $this->data['MeasureArray'] = $this->numofperact->getRowByPmid($this->params['pmid']);
- $measureArray = $this->actmeasure->getRowByPmid($this->params['pmid']);
- foreach ($this->data['MeasureArray'] as $key => $value) {
- if ($measureArray['contracttotal'] > ($value['currdone'] > 0)) {
- $this->data['MeasureArray'][$key]['lessTotal'] = round(($value['currdone'] / $measureArray['contracttotal']) * 100);
- } else {
- $this->data['MeasureArray'][$key]['lessTotal'] = 0;
- }
- }
- $this->data['pmid'] = $this->params['pmid'];
- $this->data['pid'] = $this->params['pid'];
- $this->render('w-project-section-detail', $this->data, TRUE);
- }
- public function welcome()
- {
- // if (!$this->auth->isLoggedIn())
- // return Doo::conf()->APP_URL;
- if ($this->profile->getProWithUid($this->auth->getUid())['userid'])
- return Doo::conf()->APP_URL . 'project/list';
- if (isset($_POST['welform'])) {
- $profileUserArray = $_POST;
- $profileUserArray['userid'] = $this->auth->getUid();
- $this->profile->insertProfile($profileUserArray); // 无自增字段返回0
- return Doo::conf()->APP_URL . 'project/list';
- }
- $this->render('welcome', $this->data);
- }
- public function prolist()
- {
- // if (!$this->auth->isLoggedIn())
- // return Doo::conf()->APP_URL;
- // $proArray = new stdClass();
- // $jsonpath = pathinfo($this->attfile->getMaxRow()['filepath']);
- // $extPathdir = Doo::conf()->SITE_PATH . $jsonpath['dirname'] . '/' . $jsonpath['filename'];
- // if ($handle = opendir($extPathdir)) {
- // while (false !== ($file = readdir($handle))) {
- // $filename = pathinfo($file);
- // if ($filename['extension'] == 'json')
- // $proArray = json_decode(file_get_contents($extPathdir . '/' . $file));
- // }
- // closedir($handle);
- // }
- // $this->data['proArray'] = null;
- $this->render('s-project', $this->data);
- }
- // ajax提取密码名称
- public function getAjaxSection()
- {
- if (!$this->isAjax())
- return;
- echo json_encode($_POST);
- }
- public function repasswd()
- {
- if (isset($_POST['oldpasswd']) && isset($_POST['newpasswd']) && isset($_POST['renewpasswd']) && ($_POST['newpasswd'] == $_POST['renewpasswd'])) {
- $userArray = $this->user->getRowUser($this->auth->getUid());
- if ($this->ph->CheckPassword($_POST['oldpasswd'], $userArray['upass'])) {
- if ($this->user->updatePassWd($this->auth->getUid(), $_POST['newpasswd']))
- return Doo::conf()->APP_URL . 'signout';
- }
- }
- $this->render('edit-profile-pw', $this->data, TRUE);
- }
- }
- ?>
|