UserController.php 20 KB

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