UserController.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <?php
  2. Doo::loadClass('auth');
  3. Doo::loadClass('attfile');
  4. Doo::loadClass('profile');
  5. Doo::loadClass('project');
  6. Doo::loadClass('contractact');
  7. Doo::loadClass('actmeasure');
  8. Doo::loadClass('numofperact');
  9. Doo::loadClass('user');
  10. Doo::loadClass('PasswordHash');
  11. /* * proDetail
  12. * MainController
  13. * Feel free to delete the methods and replace them with your own code.
  14. *
  15. * @author darkredz
  16. */
  17. class UserController extends DooController {
  18. private $data, $auth, $attfile, $profile, $project, $contractact, $actmeasure, $numofperact, $user, $ph;
  19. public function beforeRun($resource, $action) {
  20. // $uGroups = $this->profile->getProWithUid($this->auth->getUid());
  21. // $falg = Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  22. // if (!$falg)
  23. // return Doo::acl()->defaultFailedRoute;
  24. if ($this->auth->getUid()) {
  25. $uGroups = $this->profile->getProWithUid($this->auth->getUid());
  26. $falg = Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  27. if (!$falg)
  28. return Doo::acl()->defaultFailedRoute;
  29. }else {
  30. return Doo::acl()->defaultFailedRoute;
  31. }
  32. }
  33. public function __construct() {
  34. $this->auth = new Auth();
  35. $this->attfile = new attFile();
  36. $this->profile = new Profile();
  37. $this->project = new Project();
  38. $this->contractact = new Contractact();
  39. $this->actmeasure = new actMeasure();
  40. $this->numofperact = new NumofperAct();
  41. $this->user = new User();
  42. $this->ph = new PasswordHash(8, FALSE);
  43. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  44. $this->data['currChannle'] = 'p';
  45. $this->data['user'] = $this->profile->getProWithUid($this->auth->getUid());
  46. }
  47. /**
  48. *
  49. * @return type
  50. */
  51. public function index() {
  52. $this->data['uprofile'] = $this->profile->getProWithUid($this->auth->getUid());
  53. $this->data['uprofile']['email'] = $this->auth->getUemail();
  54. if (isset($_POST['name']) && isset($_POST['company']) && isset($_POST['jobs']) && isset($_POST['phone']) && isset($_POST['mobile'])) {
  55. $this->profile->upProfile($this->auth->getUid(), $_POST);
  56. return DOO::conf()->APP_URL . 'user/profile';
  57. }
  58. $this->render('edit-profile', $this->data, TRUE);
  59. }
  60. public function avatar() {
  61. // TODO:加入目录可否写入判断
  62. if (count($_FILES) == 3) {
  63. $result = array();
  64. $result['success'] = false;
  65. $successNum = 0;
  66. $avatarNumber = 1;
  67. $i = 0;
  68. $msg = '';
  69. $dir = 'global/avatar';
  70. while (list($key, $val) = each($_FILES)) {
  71. if ($_FILES[$key]['error'] > 0) {
  72. $msg .= $_FILES[$key]['error'];
  73. } else {
  74. $fileName = date("YmdHis") . '_' . floor(microtime() * 1000) . '_' . self::createRandomCode(8);
  75. if ($key == '__source') {
  76. $initParams = $_POST["__initParams"];
  77. $virtualPath = "$dir/php_source_$fileName.jpg";
  78. $result['sourceUrl'] = '/' . $virtualPath . $initParams;
  79. move_uploaded_file($_FILES[$key]["tmp_name"], Doo::conf()->SITE_PATH . $virtualPath);
  80. $successNum++;
  81. } else if (strpos($key, '__avatar') === 0) {
  82. $virtualPath = "$dir/php_avatar" . $avatarNumber . "_$fileName.jpg";
  83. $result['avatarUrls'][$i] = $virtualPath;
  84. if ($i == 2) {
  85. $this->profile->setAvatar($this->auth->getUid(), $result['avatarUrls'][$i]);
  86. }
  87. move_uploaded_file($_FILES[$key]["tmp_name"], $virtualPath);
  88. $successNum++;
  89. $i++;
  90. }
  91. }
  92. }
  93. $result['msg'] = $msg;
  94. if ($successNum > 0) {
  95. $result['success'] = true;
  96. }
  97. print json_encode($result);
  98. die;
  99. }
  100. $this->render('edit-profile-avtra', $this->data, TRUE);
  101. }
  102. /* * ************************************************************
  103. * 生成指定长度的随机码。
  104. * @param int $length 随机码的长度。
  105. * @access public
  106. * ************************************************************ */
  107. function createRandomCode($length) {
  108. $randomCode = "";
  109. $randomChars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  110. for ($i = 0; $i < $length; $i++) {
  111. $randomCode .= $randomChars { mt_rand(0, 35) };
  112. }
  113. return $randomCode;
  114. }
  115. public function proSection() {
  116. /**
  117. * 计量期数
  118. * 完成进度
  119. *
  120. */
  121. $this->getFav();
  122. $contractArray = $this->contractact->getRowByPid($this->params['pid']); // 获取合同段
  123. $htmlstr = NULL;
  124. foreach ($contractArray as $k => $v) {
  125. $retval = $this->actmeasure->getAllbyStid($v['stid']); // 获取标段
  126. $bdhtmlstr = NULL;
  127. $biaoduantotalmoney = 0;
  128. $currTotal = 0;
  129. $progress = $otherprogress = '0%';
  130. $currTotal = $this->numofperact->getCountTotalSTID($v['stid']);
  131. //
  132. foreach ($retval as $key => $value) {
  133. $snTotalProgress = $currTotalProgress = $lessTotalProgress = '0%';
  134. $numCount = $this->numofperact->getCountTotalnum($value['pmid']);
  135. $totalplus = $this->numofperact->getCountTotalplus($value['pmid']);
  136. $snTotal = $this->numofperact->getStopNow($value['pmid']); //截止目前
  137. $currcomTotal = $this->numofperact->getCurrTotal($value['pmid']); //截止目前
  138. if ($numCount > 0) {
  139. $nTotalProgress = number_format($snTotal['sntotal'], 2, '.', ',');
  140. $ncurrTotalProgress = number_format($currcomTotal['currtotal'], 2, '.', ',');
  141. $nlessTotalProgress = number_format($totalplus['totalplus'] - $currcomTotal['currtotal'] - $snTotal['sntotal'], 2, '.', ',');
  142. $snTotalProgress = round(($snTotal['sntotal'] / $totalplus['totalplus']) * 100) . '%';
  143. $currTotalProgress = round(($currcomTotal['currtotal'] / $totalplus['totalplus']) * 100) . '%';
  144. $lessTotalProgress = round((($totalplus['totalplus'] - $currcomTotal['currtotal'] - $snTotal['sntotal']) / $totalplus['totalplus']) * 100) . '%';
  145. }
  146. $biaoduantotalmoney += $value['contracttotal'];
  147. $totalmoney = number_format($value['contracttotal'], 2, '.', ',');
  148. $bdhtmlstr .='
  149. <thead>
  150. <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>
  151. <tbody>
  152. <tr>
  153. <td><a href="/project/1/section/' . $value['pmid'] . '/detail">' . $value['pmname'] . '</a></td>
  154. <td class="">共 ' . $numCount . ' 期(本期 <span class="colOrange">审批中</span>)</td>
  155. <td class="taR">¥' . $totalmoney . '</td>
  156. <td>
  157. <div class="progress">
  158. <div class="bar bar-success" style="width: ' . $snTotalProgress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="截止本期累计完成:¥' . $nTotalProgress . '">' . $snTotalProgress . '</div>
  159. <div class="bar" style="width:' . $currTotalProgress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="本期完成:¥' . $ncurrTotalProgress . '">' . $currTotalProgress . '</div>
  160. <div class="bar bar-gary" style="width:' . $lessTotalProgress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="未完成:¥' . $nlessTotalProgress . '">' . $lessTotalProgress . '</div>
  161. </div>
  162. </td>
  163. </tr>';
  164. }
  165. if ($biaoduantotalmoney > 0 && ($currTotal['totalplus'] > 0)) {
  166. $nprogress = number_format($currTotal['totalplus'], 2, '.', ',');
  167. $notherprogress = number_format($biaoduantotalmoney - $currTotal['totalplus'], 2, '.', ',');
  168. $progress = round(($currTotal['totalplus'] / $biaoduantotalmoney) * 100) . '%';
  169. $otherprogress = round((($biaoduantotalmoney - $currTotal['totalplus']) / $biaoduantotalmoney) * 100) . '%';
  170. $biaoduantotalmoney = number_format($biaoduantotalmoney, 2, '.', ',');
  171. }
  172. $htmlstr .= '<div class="project">
  173. <div class="proSection">
  174. <table class="table">
  175. <thead>
  176. <tr>
  177. <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>
  178. <td width="90">总价:</td><td width="165">¥<b style="font-size:16px">' . $biaoduantotalmoney . '</b></td>
  179. <td width="60">完成进度:</td><td><div class="progress">
  180. <div class="bar bar-success" style="width:' . $progress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="累计完成:¥' . $nprogress . '">' . $progress . '</div>
  181. <div class="bar bar-danger" style="width:' . $otherprogress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="未完成:¥' . $notherprogress . '">' . $otherprogress . '</div>
  182. </div></td>
  183. </tr>
  184. </thead>
  185. </table>
  186. <table class="table table-striped table-hover">
  187. ' . $bdhtmlstr . '
  188. </tbody>
  189. </table>
  190. </div>
  191. </div>';
  192. }
  193. $this->data['htmlstr'] = $htmlstr;
  194. if (isset($_POST['secname']) && $_POST['secname']) {
  195. $this->contractact->insertContract($this->params['pid'], $this->auth->getUid(), $_POST['secname']);
  196. return Doo::conf()->APP_URL . 'project/' . $this->params['pid'] . '/section';
  197. }
  198. $this->data['pid'] = $this->params['pid'];
  199. $this->render('w-project-section', $this->data, TRUE);
  200. }
  201. Function fNumber($number) {
  202. if ($number == '')
  203. Return "-";
  204. $nlen = strlen($number);
  205. while ($nlen > 3) {
  206. $fNumber = "," . substr($number, $nlen - 3, 3);
  207. $number = substr($number, 0, -3);
  208. $nlen = strlen($number);
  209. }
  210. if ($nlen <= 3) {
  211. $fNumber = $number . $fNumber;
  212. }
  213. Return $fNumber;
  214. }
  215. private function getFav() {
  216. $proArray = $this->project->getAll();
  217. $this->data['othrPro'] = [];
  218. foreach ($proArray as $key => $value) {
  219. if ($value['pid'] == $this->params['pid']) {
  220. $this->data['currProName'] = $value['pname'];
  221. $this->data['currProID'] = $value['pid'];
  222. } else {
  223. $this->data['othrPro'][] = $proArray[$key];
  224. }
  225. }
  226. }
  227. public function proSectionMeasure() {
  228. //此处未做更改,JSON文件已经固定名称
  229. $jsonpath = pathinfo($this->attfile->getMaxRow()['filepath']);
  230. if (isset($jsonpath['dirname'])) {
  231. $extPathdir = Doo::conf()->SITE_PATH . $jsonpath['dirname'] . '/' . $jsonpath['filename'];
  232. if ($handle = opendir($extPathdir)) {
  233. while (false !== ($file = readdir($handle))) {
  234. $filename = NULL;
  235. $filename = pathinfo($file);
  236. if ($filename['extension'] == 'json')
  237. $proArray = json_decode(file_get_contents($extPathdir . '/' . $file), TRUE, JSON_UNESCAPED_UNICODE);
  238. }
  239. closedir($handle);
  240. }
  241. $this->data['proArray'] = $proArray['Bills'];
  242. }else {
  243. $this->data['proArray'] = [];
  244. }
  245. $this->data['mpid'] = $this->params['mpid'];
  246. $this->data['pid'] = $this->params['pid'];
  247. $this->render('w-project-section-measure', $this->data, TRUE);
  248. }
  249. public function substr_replace_cn($string, $repalce = '*', $start = 0, $len = 0) {
  250. $count = mb_strlen($string, 'UTF-8'); //此处传入编码,建议使用utf-8。此处编码要与下面mb_substr()所使用的一致
  251. if (!$count) {
  252. return $string;
  253. }
  254. if ($len == 0) {
  255. $end = $count; //传入0则替换到最后
  256. } else {
  257. $end = $start + $len; //传入指定长度则为开始长度+指定长度
  258. }
  259. $i = 0;
  260. $returnString = '';
  261. while ($i < $count) { //循环该字符串
  262. $tmpString = mb_substr($string, $i, 1, 'UTF-8'); // 与mb_strlen编码一致
  263. if ($start <= $i && $i < $end) {
  264. $returnString .= $repalce;
  265. } else {
  266. $returnString .= $tmpString;
  267. }
  268. $i ++;
  269. }
  270. return $returnString;
  271. }
  272. function unicode_encode($name) {//to Unicode
  273. $name = iconv('UTF-8', 'UCS-2', $name);
  274. $len = strlen($name);
  275. $str = '';
  276. for ($i = 0; $i < $len - 1; $i = $i + 2) {
  277. $c = $name[$i];
  278. $c2 = $name[$i + 1];
  279. if (ord($c) > 0) {// 两个字节的字
  280. $str .= '\\' . base_convert(ord($c), 10, 16) . base_convert(ord($c2), 10, 16);
  281. } else {
  282. $str .= $c2;
  283. }
  284. }
  285. $str = strtoupper($str);
  286. return $str;
  287. }
  288. function unicode_decode($name) {//Unicode to
  289. $pattern = '/([\w]+)|(\\\u([\w]{4}))/i';
  290. preg_match_all($pattern, $name, $matches);
  291. if (!empty($matches)) {
  292. $name = '';
  293. for ($j = 0; $j < count($matches[0]); $j++) {
  294. $str = $matches[0][$j];
  295. if (strpos($str, '\\u') === 0) {
  296. $code = base_convert(substr($str, 2, 2), 16, 10);
  297. $code2 = base_convert(substr($str, 4), 16, 10);
  298. $c = chr($code) . chr($code2);
  299. $c = iconv('UCS-2', 'UTF-8', $c);
  300. $name .= $c;
  301. } else {
  302. $name .= $str;
  303. }
  304. }
  305. }
  306. return $name;
  307. }
  308. public function proDetail() {
  309. // 面包屑导航项目
  310. $this->data['currproArray'] = $this->data['allproArray'] = NULL;
  311. $allproArray = $this->project->getAll();
  312. foreach ($allproArray as $kk => $vv) {
  313. if ($vv['pid'] == $this->params['pid']) {
  314. $this->data['currproArray'] = $vv;
  315. } else {
  316. $this->data['allproArray'][] = $vv;
  317. }
  318. }
  319. // 面包屑导航合同
  320. $conArray = $this->contractact->getAll();
  321. $measureArray = $this->actmeasure->getRowByPmid($this->params['pmid']);
  322. if (isset($measureArray['stid'])) {
  323. foreach ($conArray as $kkk => $vvv) {
  324. if ($vvv['stid'] == $measureArray['stid']) {
  325. $this->data['currconArray'] = $vvv;
  326. } else {
  327. $this->data['allconArray'][] = $vvv;
  328. }
  329. }
  330. } else {
  331. $this->data['currconArray'] = $this->data['allconArray'] = NULL;
  332. }
  333. // 面包屑导航标段
  334. $this->data['curractmeasureArray'] = NULL;
  335. $this->data['allactmeasureArray'] = [];
  336. $actmeasureArray = $this->actmeasure->getAll();
  337. foreach ($actmeasureArray as $kkkk => $vvvv) {
  338. if ($vvvv['stid'] == $measureArray['stid']) {
  339. if (($vvvv['pmid'] == $this->params['pmid'])) {
  340. $this->data['curractmeasureArray'] = $vvvv;
  341. } else {
  342. $this->data['allactmeasureArray'][] = $vvvv;
  343. }
  344. }
  345. }
  346. // 图标
  347. $this->data['MeasureArray'] = $this->numofperact->getRowByPmid($this->params['pmid']);
  348. $measureArray = $this->actmeasure->getRowByPmid($this->params['pmid']);
  349. foreach ($this->data['MeasureArray'] as $key => $value) {
  350. if ($measureArray['contracttotal'] > ($value['currdone'] > 0)) {
  351. $this->data['MeasureArray'][$key]['lessTotal'] = round(($value['currdone'] / $measureArray['contracttotal']) * 100);
  352. } else {
  353. $this->data['MeasureArray'][$key]['lessTotal'] = 0;
  354. }
  355. }
  356. $this->data['pmid'] = $this->params['pmid'];
  357. $this->data['pid'] = $this->params['pid'];
  358. $this->render('w-project-section-detail', $this->data, TRUE);
  359. }
  360. public function welcome() {
  361. // if (!$this->auth->isLoggedIn())
  362. // return Doo::conf()->APP_URL;
  363. if ($this->profile->getProWithUid($this->auth->getUid())['userid'])
  364. return Doo::conf()->APP_URL . 'project/list';
  365. if (isset($_POST['welform'])) {
  366. $profileUserArray = $_POST;
  367. $profileUserArray['userid'] = $this->auth->getUid();
  368. $this->profile->insertProfile($profileUserArray); // 无自增字段返回0
  369. return Doo::conf()->APP_URL . 'project/list';
  370. }
  371. $this->render('welcome', $this->data);
  372. }
  373. public function prolist() {
  374. // if (!$this->auth->isLoggedIn())
  375. // return Doo::conf()->APP_URL;
  376. // $proArray = new stdClass();
  377. // $jsonpath = pathinfo($this->attfile->getMaxRow()['filepath']);
  378. // $extPathdir = Doo::conf()->SITE_PATH . $jsonpath['dirname'] . '/' . $jsonpath['filename'];
  379. // if ($handle = opendir($extPathdir)) {
  380. // while (false !== ($file = readdir($handle))) {
  381. // $filename = pathinfo($file);
  382. // if ($filename['extension'] == 'json')
  383. // $proArray = json_decode(file_get_contents($extPathdir . '/' . $file));
  384. // }
  385. // closedir($handle);
  386. // }
  387. // $this->data['proArray'] = null;
  388. $this->render('s-project
  389. ', $this->data);
  390. }
  391. // ajax提取密码名称
  392. public function getAjaxSection() {
  393. if (!$this->isAjax())
  394. return;
  395. echo json_encode($_POST);
  396. }
  397. public function repasswd() {
  398. if (isset($_POST['oldpasswd']) && isset($_POST['newpasswd']) && isset($_POST['renewpasswd']) && ($_POST['newpasswd'] == $_POST['renewpasswd'])) {
  399. $userArray = $this->user->getRowUser($this->auth->getUid());
  400. if ($this->ph->CheckPassword($_POST['oldpasswd'], $userArray['upass'])) {
  401. if ($this->user->updatePassWd($this->auth->getUid(), $_POST['newpasswd']))
  402. return Doo::conf()->APP_URL . 'signout';
  403. }
  404. }
  405. $this->render('edit-profile-pw', $this->data, TRUE);
  406. }
  407. }
  408. ?>