AdminController.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class AdminController extends DooController {
  6. public $staff;
  7. public $nature = array (
  8. '1' => '设计',
  9. '2' => '造价管理',
  10. '3' => '业主',
  11. '4' => '交通局',
  12. '5' => '公路局',
  13. '6' => '审计',
  14. '7' => '财政',
  15. '8' => '审核',
  16. '9' => '施工',
  17. '10' => '咨询',
  18. '11' => '招标代理',
  19. '12' => '监理',
  20. '13' => '学校',
  21. '14' => '个人',
  22. '15' => '合作伙伴'
  23. );
  24. public $tooltip = array (
  25. '1' => array (
  26. 'L',
  27. '点击筛选标签'
  28. ),
  29. '2' => array (
  30. 'M',
  31. '点击筛选标签'
  32. ),
  33. '3' => array (
  34. 'N',
  35. '点击筛选标签'
  36. ),
  37. '4' => array (
  38. 'O',
  39. '点击筛选标签'
  40. ),
  41. '5' => array (
  42. 'P',
  43. '点击筛选标签'
  44. ),
  45. '6' => array (
  46. 'Q',
  47. '点击筛选标签'
  48. ),
  49. '7' => array (
  50. 'R',
  51. '点击筛选标签'
  52. )
  53. );
  54. public $webPath = "http://cld.smartcost.com.cn/upload/emailAnnex/";
  55. function __construct() {
  56. if (isset ( $_COOKIE ["adStaff"] )) {
  57. if (! empty ( $_COOKIE ["adStaff"] )) {
  58. Doo::loadModel ( 'staff' );
  59. $staff = new staff ();
  60. $this->staff = $staff->getUserByIdList ( $_COOKIE ["adStaff"] );
  61. if ($this->staff [0] ['isadmin'] == 1 && $this->staff [0] ['username'] == 'admin') {
  62. return "/adminoffice";
  63. }
  64. }
  65. }
  66. Doo::loadCore ( 'uri/DooUriRouter' );
  67. $router = new DooUriRouter ();
  68. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  69. if ($routeRs ['1'] != "adlogin") {
  70. header ( 'Content-Type:text/html;charset=utf-8' );
  71. @header ( "Location: /adlogin" );
  72. }
  73. }
  74. function adlogin() {
  75. $passwork = isset ( $_POST ['passwork'] ) ? $_POST ['passwork'] : "";
  76. $uid = isset ( $_POST ['user'] ) ? $_POST ['user'] : "";
  77. Doo::loadModel ( 'staff' );
  78. $staff = new staff ();
  79. if (! empty ( $passwork )) {
  80. $userinfo = $staff->getOne ( array (
  81. 'where' => "username='admin'",
  82. 'asArray' => true
  83. ) );
  84. if (! empty ( $userinfo )) {
  85. if ($userinfo ['username'] == $uid && $userinfo ['passwork'] == md5 ( $passwork )) {
  86. setcookie ( "adStaff", $userinfo ['sid'], time () + 36000, "/" );
  87. return "/adminoffice";
  88. }
  89. }
  90. }
  91. $data ['staff'] = "";
  92. $data ['login'] = "";
  93. if (! empty ( $passwork ))
  94. $data ['login'] = "inputErrow";
  95. $this->render ( "/admin/adminLogin", $data );
  96. }
  97. function adout() {
  98. setcookie ( "adStaff", "", time () - 3600, "/" );
  99. return "/adlogin";
  100. }
  101. function adminPW() {
  102. $msg = $this->params ['msg'] ? $this->params ['msg'] : "";
  103. $data ['msg'] = "msg";
  104. $data ['memu'] = "adminpw";
  105. $data ['staff'] = $this->staff;
  106. $data ['msg'] = urldecode ( $this->params ['msg'] );
  107. $this->render ( "/admin/admin-admininfo", $data );
  108. }
  109. function upAdP() {
  110. $opw = $this->get_args ( 'opw' ) ? $this->get_args ( 'opw' ) : "";
  111. $npw1 = $this->get_args ( 'npw1' ) ? $this->get_args ( 'npw1' ) : "";
  112. $npw2 = $this->get_args ( 'npw2' ) ? $this->get_args ( 'npw2' ) : "";
  113. if (! empty ( $opw )) {
  114. Doo::loadModel ( 'staff' );
  115. $staff = new staff ();
  116. $userinfo = $staff->getOne ( array (
  117. 'where' => "username='admin'",
  118. 'asArray' => true
  119. ) );
  120. if (! empty ( $userinfo )) {
  121. if ($userinfo ['sid'] == $_COOKIE ["adStaff"] && $userinfo ['passwork'] == md5 ( $opw )) {
  122. if (($npw1 == $npw2) && ($npw1 != "")) {
  123. $staff->passwork = md5 ( $npw1 );
  124. $staff->update ( array (
  125. 'where' => "sid='" . $_COOKIE ["adStaff"] . "'"
  126. ) );
  127. return "/adminpw/" . urlencode ( '密码修改成功' );
  128. } else
  129. return "/adminpw/" . urlencode ( '新密码不一致' );
  130. } else
  131. return "/adminpw/" . urlencode ( '旧密码不正确' );
  132. } else
  133. return "/adminpw/" . urlencode ( '未找到用户' );
  134. } else
  135. return "/adminpw/" . urlencode ( '请输入旧密码' );
  136. }
  137. function adminoffice() {
  138. $data ['memu'] = "adminoffice";
  139. $data ['staff'] = $this->staff;
  140. Doo::loadModel ( 'L_category' );
  141. Doo::loadModel ( 'staff' );
  142. Doo::loadModel ( 'district' );
  143. $district = new district ();
  144. $staff = new staff ();
  145. $L_category = new L_category ();
  146. $data ['category'] = $L_category->getCategory ();
  147. $data ['district'] = $district->get_lv ( 1 );
  148. foreach ( $data ['category'] as $key => $value ) {
  149. $data ['category'] [$key] ['count'] = $staff->count ( array (
  150. 'where' => 'cid=' . $value ['cid']
  151. ) );
  152. }
  153. $data ['msg'] = urldecode ( $this->params ['msg'] );
  154. $this->render ( "/admin/admin_group", $data );
  155. }
  156. function addCategory() {
  157. $msg = "添加成功";
  158. $title = isset ( $_POST ['title'] ) ? $_POST ['title'] : "";
  159. $district = isset ( $_POST ['district'] ) ? $_POST ['district'] : "";
  160. if (! empty ( $title ) && ! empty ( $district )) {
  161. Doo::loadModel ( 'L_category' );
  162. $L_category = new L_category ();
  163. $L_category->title = $title;
  164. $L_category->districtid = $district;
  165. $L_category->insert ();
  166. } else {
  167. $msg = "请输入正确的信息";
  168. }
  169. return "/adminoffice/" . $msg;
  170. }
  171. function adminuser() {
  172. $data ['memu'] = "adminuser";
  173. $data ['staff'] = $this->staff;
  174. Doo::loadModel ( 'L_category' );
  175. Doo::loadModel ( 'staff' );
  176. $staff = new staff ();
  177. $L_category = new L_category ();
  178. $data ['category'] = $L_category->getCategory ();
  179. $data ['stafflist'] = $staff->getStaff ();
  180. $data ['staff'] = $this->staff;
  181. $this->render ( "/admin/admin_user", $data );
  182. }
  183. function adduser() {
  184. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  185. $password = $this->get_args ( 'password' ) ? $this->get_args ( 'password' ) : "";
  186. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  187. $hiredate = $this->get_args ( 'hiredate' ) ? $this->get_args ( 'hiredate' ) : "";
  188. $nature = is_numeric ( $this->get_args ( 'nature' ) ) ? $this->get_args ( 'nature' ) : 1;
  189. if (! empty ( $username ) && ! empty ( $password ) && ! empty ( $cid ) && ! empty ( $hiredate ) && ! empty ( $nature )) {
  190. Doo::loadModel ( 'L_category' );
  191. Doo::loadModel ( 'staff' );
  192. Doo::loadModel ( 'tag' );
  193. Doo::loadModel ( 'holidaystaff' );
  194. $staff = new staff ();
  195. $L_category = new L_category ();
  196. // 加入默认总部分类
  197. $cagegory = $L_category->getCategoryById ( $cid );
  198. // 根据这个分类加入管理权限
  199. if ($cagegory [0] ['defult'] == 1) {
  200. $staff->isadmin = 1;
  201. }
  202. $staff->username = $username;
  203. $staff->passwork = md5 ( $password );
  204. $staff->cid = $cagegory [0] ['cid'];
  205. $staff->category = $cagegory [0] ['title'];
  206. $staff->hiredate = $hiredate;
  207. $staff->nature = $nature;
  208. $id = $staff->insert ();
  209. $holidaystaff = new HStaff ();
  210. $holidaystaff->uid = $id;
  211. $holidaystaff->insert();
  212. $staffmsg = $staff->getUserById($id);
  213. $this->updateAnnualLeave($staffmsg[0]);
  214. for ($i=1;$i<=7;$i++){
  215. $tag = new tag ();
  216. $tag->name = "个人标签";
  217. $tag->sid = $id;
  218. $tag->colorid = $i;
  219. $tag->insert ();
  220. }
  221. }
  222. return "/adminuser";
  223. }
  224. function adminEdiUser() {
  225. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  226. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  227. if (! empty ( $sid )) {
  228. $data ['msg'] = urldecode ( $msg );
  229. Doo::loadModel ( 'L_category' );
  230. Doo::loadModel ( 'staff' );
  231. $staff = new staff ();
  232. $L_category = new L_category ();
  233. $data ['newPw'] = '';
  234. $data ['staffInfo'] = $staff->getUserById ( $sid );
  235. $data ['category'] = $L_category->getCategory ();
  236. $data ['staff'] = $this->staff;
  237. $data ['memu'] = "adminuser";
  238. $this->render ( "/admin/admin_EdiUser", $data );
  239. } else
  240. return "/adminuser";
  241. }
  242. function adminResetUserPw() {
  243. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  244. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  245. if (! empty ( $sid )) {
  246. $data ['msg'] = urldecode ( $msg );
  247. Doo::loadModel ( 'L_category' );
  248. Doo::loadModel ( 'staff' );
  249. $staff = new staff ();
  250. $L_category = new L_category ();
  251. $newPw = $this->getRandChar ( 6 );
  252. $staff->sid = $sid;
  253. $staff->passwork = md5 ( $newPw );
  254. $staff->update ();
  255. $data ['newPw'] = $newPw;
  256. $data ['staffInfo'] = $staff->getUserById ( $sid );
  257. $data ['category'] = $L_category->getCategory ();
  258. $data ['staff'] = $this->staff;
  259. $data ['memu'] = "adminuser";
  260. $this->render ( "/admin/admin_EdiUser", $data );
  261. } else
  262. return "/adminuser";
  263. }
  264. function adminDoEdiUser() {
  265. $sid = is_numeric ( $this->get_args ( 'sid' ) ) ? $this->get_args ( 'sid' ) : 0;
  266. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  267. $gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "";
  268. $qq = is_numeric ( $this->get_args ( 'qq' ) ) ? $this->get_args ( 'qq' ) : 0;
  269. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  270. $telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : "";
  271. $email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
  272. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  273. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  274. $hiredate = $this->get_args ( 'hiredate' ) ? $this->get_args ( 'hiredate' ) : "";
  275. if (! empty ( $sid )) {
  276. $msg = "";
  277. Doo::loadModel ( 'L_category' );
  278. Doo::loadModel ( 'staff' );
  279. $staff = new staff ();
  280. $L_category = new L_category ();
  281. $categoryInfo = $L_category->getCategoryById ( $cid );
  282. $staff->sid = $sid;
  283. if ($cid != 0) {
  284. $staff->cid = $categoryInfo [0] ['cid'];
  285. $staff->category = $categoryInfo [0] ['title'];
  286. }
  287. if ($categoryInfo [0] ['defult'] == 1) {
  288. $staff->isadmin = 1;
  289. } else {
  290. $staff->isadmin = 0;
  291. }
  292. if (! empty ( $username ))
  293. $staff->username = $username;
  294. if (! empty ( $gender ))
  295. $staff->gender = $gender;
  296. if (! empty ( $qq ) && is_numeric ( $qq ))
  297. $staff->qq = $qq;
  298. if (! empty ( $phone ))
  299. $staff->phone = $phone;
  300. if (! empty ( $telephone ))
  301. $staff->telephone = $telephone;
  302. if (! empty ( $email ) && filter_var ( $email, FILTER_VALIDATE_EMAIL ))
  303. $staff->email = $email;
  304. else
  305. $msg = "邮箱不正确";
  306. if (! empty ( $hiredate ))
  307. $staff->hiredate = $hiredate;
  308. $staff->nature = $nature;
  309. $staff->update ();
  310. $staffmsg = $staff->getUserById ( $sid );
  311. $this->updateAnnualLeave ( $staffmsg [0] );
  312. return "/edi/user/" . $sid . "/" . $msg;
  313. } else {
  314. return "/adminuser";
  315. }
  316. }
  317. function adminDoAddCategory() {
  318. $sid = is_numeric ( $this->get_args ( 'sid' ) ) ? $this->get_args ( 'sid' ) : 0;
  319. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  320. if (! empty ( $sid )) {
  321. Doo::loadModel ( 'L_category' );
  322. Doo::loadModel ( 'staff' );
  323. $staff = new staff ();
  324. $L_category = new L_category ();
  325. $stfInfo = $staff->getOne ( array (
  326. 'where' => 'sid =' . $sid,
  327. 'asArray' => true
  328. ) );
  329. if ($stfInfo ['cid'] == $cid)
  330. return "/adminuser";
  331. $othcid = explode ( ',', $stfInfo ['othercid'] );
  332. if (in_array ( $cid, $othcid ))
  333. return "/adminuser";
  334. array_push ( $othcid, $cid );
  335. $strCid = implode ( ',', array_filter ( $othcid ) );
  336. $catename = $L_category->getCategoryById ( $cid );
  337. $othcategory = explode ( ',', $stfInfo ['othercategory'] );
  338. array_push ( $othcategory, $catename [0] ['title'] );
  339. $strcategory = implode ( ',', array_filter ( $othcategory ) );
  340. $staff->sid = $sid;
  341. $staff->othercid = $strCid;
  342. $staff->othercategory = $strcategory;
  343. $staff->update ();
  344. }
  345. return "/adminuser";
  346. }
  347. function adminDeleteUser() {
  348. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  349. if (! empty ( $sid )) {
  350. Doo::loadModel ( 'staff' );
  351. $staff = new staff ();
  352. $staff->sid = $sid;
  353. $staff->delete ();
  354. }
  355. return "/adminuser";
  356. }
  357. function adminproduct() {
  358. $data ['memu'] = "adminproduct";
  359. $data ['staff'] = $this->staff;
  360. Doo::loadModel ( 'product' );
  361. Doo::loadModel ( 'longle' );
  362. $product = new product ();
  363. $longle = new longle ();
  364. $data ['product'] = $product->getProudct ();
  365. foreach ( $data ['product'] as $key => $value ) {
  366. $data ['product'] [$key] ['count'] = $longle->count ( array (
  367. 'where' => 'product="' . $value ['title'] . '"'
  368. ) );
  369. }
  370. $this->render ( "/admin/admin_product", $data );
  371. }
  372. function addproduct() {
  373. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  374. if (! empty ( $title )) {
  375. Doo::loadModel ( 'product' );
  376. $product = new product ();
  377. $product->title = $title;
  378. $product->insert ();
  379. }
  380. return "/adminproduct";
  381. }
  382. function adminDeleteProduct() {
  383. $pid = is_numeric ( $this->params ['pid'] ) ? $this->params ['pid'] : 0;
  384. if (! empty ( $pid )) {
  385. Doo::loadModel ( 'product' );
  386. $product = new product ();
  387. $product->pid = $pid;
  388. $product->delete ();
  389. }
  390. return "/adminproduct";
  391. }
  392. function adminEdiProduct() {
  393. $pid = is_numeric ( $this->params ['pid'] ) ? $this->params ['pid'] : 0;
  394. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  395. if (! empty ( $pid )) {
  396. $data ['msg'] = urldecode ( $msg );
  397. Doo::loadModel ( 'product' );
  398. $product = new product ();
  399. $data ['productInfo'] = $product->getProductById ( $pid );
  400. $data ['memu'] = "adminproduct";
  401. $data ['staff'] = $this->staff;
  402. $this->render ( "/admin/admin_EdiProduct", $data );
  403. } else
  404. return "/adminproduct";
  405. }
  406. function adminDoEdiProduct() {
  407. $pid = is_numeric ( $this->get_args ( 'pid' ) ) ? $this->get_args ( 'pid' ) : "";
  408. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  409. $typeid = $this->get_args ( 'typeid' ) ? $this->get_args ( 'typeid' ) : "";
  410. if (! empty ( $pid ) && ! empty ( $title ) && ! empty ( $typeid )) {
  411. $msg = "";
  412. Doo::loadModel ( 'product' );
  413. $product = new product ();
  414. $product->pid = $pid;
  415. $product->title = $title;
  416. $product->typeid = $typeid;
  417. $product->update ();
  418. return "/adminproduct";
  419. } else {
  420. return "/adminproduct";
  421. }
  422. }
  423. function adminverify() {
  424. Doo::loadModel ( 'staff' );
  425. Doo::loadModel ( "verify" );
  426. $verify = new verify ();
  427. $staff = new staff ();
  428. Doo::loadModel ( "role" );
  429. $role = new role ();
  430. $data ['staffList'] = $staff->find ( array (
  431. 'select' => 'username,sid,avatar',
  432. 'asArray' => true
  433. ) );
  434. $list = $verify->find ( array (
  435. 'asArray' => true
  436. ) );
  437. $roleList = $role->find ( array (
  438. 'asArray' => true
  439. ) );
  440. foreach ( $roleList as $key => $value ) {
  441. $staffList = json_decode ( $value ['staff'] );
  442. foreach ( $staffList as $k => $v ) {
  443. $staffList [$k] = substr ( strstr ( $v, '_' ), 1 );
  444. }
  445. $roleList [$key] ['staff'] = implode ( ',', $staffList );
  446. }
  447. foreach ( $list as $key => $value ) {
  448. $name = json_decode ( $value ['staff'] );
  449. $list [$key] ['staff'] = "";
  450. foreach ( $name as $k => $v ) {
  451. if ($v [1] == 'ROLE') {
  452. $roleInfo = $role->getOne ( array (
  453. 'where' => 'rid = "' . $v [0] . '"',
  454. 'asArray' => true
  455. ) );
  456. $v [1] = $roleInfo ['name'];
  457. }
  458. $list [$key] ['staff'] .= " " . $v [1];
  459. }
  460. }
  461. $data ['roleList'] = $roleList;
  462. $data ['verify'] = $list;
  463. $data ['memu'] = "verify";
  464. $data ['staff'] = $this->staff;
  465. $this->render ( "/admin/admin_reportGroup", $data );
  466. }
  467. function addVerify() {
  468. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  469. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  470. $uidlist = $this->get_args ( 'uidlist' ) ? $this->get_args ( 'uidlist' ) : "";
  471. $uidlist = explode ( ",", $uidlist );
  472. Doo::loadModel ( "role" );
  473. $role = new role ();
  474. $list = array ();
  475. foreach ( $uidlist as $key => $value ) {
  476. $info = explode ( ":", $value );
  477. if ($info [1] == 'ROLE') {
  478. $roleInfo = $role->getOne ( array (
  479. 'where' => 'rid = "' . $info [0] . '"',
  480. 'asArray' => true
  481. ) );
  482. array_push ( $info, $roleInfo ['staff'] );
  483. }
  484. array_push ( $list, $info );
  485. }
  486. if (! empty ( $description ) && ! empty ( $list )) {
  487. Doo::loadModel ( "verify" );
  488. $verify = new verify ();
  489. $verify->description = $description;
  490. $verify->staff = json_encode ( $list );
  491. $verify->insert ();
  492. }
  493. return "/adminverify";
  494. }
  495. function adminRole() {
  496. Doo::loadModel ( 'staff' );
  497. $staff = new staff ();
  498. Doo::loadModel ( "verify" );
  499. $verify = new verify ();
  500. Doo::loadModel ( "role" );
  501. $role = new role ();
  502. $data ['staffList'] = $staff->find ( array (
  503. 'select' => 'username,sid,avatar',
  504. 'asArray' => true
  505. ) );
  506. $list = $verify->find ( array (
  507. 'asArray' => true
  508. ) );
  509. $roleList = $role->find ( array (
  510. 'asArray' => true
  511. ) );
  512. foreach ( $list as $key => $value ) {
  513. $name = json_decode ( $value ['staff'] );
  514. $list [$key] ['staff'] = "";
  515. foreach ( $name as $k => $v ) {
  516. $list [$key] ['staff'] .= " " . $v [1];
  517. }
  518. }
  519. foreach ( $roleList as $key => $value ) {
  520. $staff = json_decode ( $value ['staff'] );
  521. foreach ( $staff as $k => $v ) {
  522. // print_r($info);
  523. // $staff[$k]=substr(strstr($v, '_'), 1);
  524. $info = explode ( '_', $v );
  525. $staff [$k] = $info;
  526. }
  527. $roleList [$key] ['list'] = $staff;
  528. }
  529. $data ['roleList'] = $roleList;
  530. $data ['verify'] = $list;
  531. $data ['memu'] = "verify";
  532. $data ['staff'] = $this->staff;
  533. $this->render ( "/admin/adminReportGroupRole", $data );
  534. }
  535. function addRole() {
  536. $name = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  537. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  538. $list = array ();
  539. foreach ( $staff as $key => $value ) {
  540. $na = explode ( ":", $value );
  541. array_push ( $list, $na [0] . '_' . $na [1] );
  542. }
  543. if (! empty ( $name ) && ! empty ( $list )) {
  544. Doo::loadModel ( "role" );
  545. $role = new role ();
  546. $role->name = $name;
  547. $role->staff = json_encode ( $list );
  548. $role->insert ();
  549. }
  550. return "/adminRole";
  551. }
  552. function delRole() {
  553. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  554. if (! empty ( $rid )) {
  555. Doo::loadModel ( "role" );
  556. $role = new role ();
  557. $role->delete ( array (
  558. 'where' => 'rid="' . $rid . '"'
  559. ) );
  560. }
  561. return "/adminRole";
  562. }
  563. function updateRole() {
  564. $oldStaff = $this->get_args ( 'oldStaff' ) ? $this->get_args ( 'oldStaff' ) : "";
  565. $newStaff = $this->get_args ( 'newStaff' ) ? $this->get_args ( 'newStaff' ) : "";
  566. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  567. if (! empty ( $oldStaff ) && ! empty ( $newStaff ) && ! empty ( $rid )) {
  568. Doo::loadModel ( "role" );
  569. $role = new role ();
  570. $roleInfo = $role->getOne ( array (
  571. 'where' => 'rid = "' . $rid . '"',
  572. 'asArray' => true
  573. ) );
  574. $staffList = json_decode ( $roleInfo ['staff'], true );
  575. foreach ( $staffList as $key => $value ) {
  576. if ($value == $oldStaff) {
  577. $staffList [$key] = $newStaff;
  578. break;
  579. }
  580. }
  581. $role->staff = json_encode ( $staffList );
  582. $role->update ( array (
  583. 'where' => 'rid = "' . $rid . '"'
  584. ) );
  585. }
  586. return "/adminRole";
  587. }
  588. function adminExecute() {
  589. Doo::loadModel ( 'staff' );
  590. $staff = new staff ();
  591. Doo::loadModel ( "execute" );
  592. $execute = new execute ();
  593. $data ['staffList'] = $staff->find ( array (
  594. 'select' => 'username,sid,avatar',
  595. 'asArray' => true
  596. ) );
  597. $list = $execute->find ( array (
  598. 'asArray' => true
  599. ) );
  600. $execute = array (
  601. '借款执行人' => '',
  602. '借款费用执行人' => '',
  603. '报销单执行人' => '',
  604. '对公汇款执行人' => ''
  605. );
  606. foreach ( $list as $key => $value ) {
  607. $name = json_decode ( $value ['staff'] );
  608. $staffString = "";
  609. if (! empty ( $name )) {
  610. foreach ( $name as $k => $v ) {
  611. $staffString .= " " . $v [1] . '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/delExecute/' . $v [0] . '/' . $value ['eid'] . '\'" title="删除" class="icon-">k</a>';
  612. }
  613. }
  614. foreach ( $execute as $k => $v ) {
  615. if ($k == $value ['mold']) {
  616. $execute [$k] = $name = $staffString;
  617. }
  618. }
  619. }
  620. // print_r($execute);die;
  621. $data ['execute'] = $execute;
  622. $data ['memu'] = "verify";
  623. $data ['staff'] = $this->staff;
  624. $this->render ( "/admin/adminCarriedout", $data );
  625. }
  626. function addExecute() {
  627. $mold = $this->get_args ( 'mold' ) ? $this->get_args ( 'mold' ) : "";
  628. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  629. if (! empty ( $mold ) && ! empty ( $staff )) {
  630. Doo::loadModel ( "execute" );
  631. $execute = new execute ();
  632. $executeInfo = $execute->getOne ( array (
  633. 'where' => 'mold ="' . $mold . '" ',
  634. 'asArray' => true
  635. ) );
  636. if (empty ( $executeInfo )) {
  637. $list = array ();
  638. foreach ( $staff as $key => $value ) {
  639. $info = explode ( ":", $value );
  640. array_push ( $list, $info );
  641. }
  642. $execute->mold = $mold;
  643. $execute->staff = json_encode ( $list );
  644. $execute->insert ();
  645. } else {
  646. $list = json_decode ( $executeInfo ['staff'], true );
  647. foreach ( $staff as $k => $v ) {
  648. $info = explode ( ":", $v );
  649. foreach ( $list as $key => $value ) {
  650. if ($value [1] == $info [1]) {
  651. unset ( $staff [$k] );
  652. break;
  653. }
  654. }
  655. }
  656. foreach ( $staff as $k => $v ) {
  657. $info = explode ( ":", $v );
  658. array_push ( $list, $info );
  659. }
  660. $execute->staff = json_encode ( $list );
  661. $execute->update ( array (
  662. 'where' => 'eid = ' . $executeInfo ['eid']
  663. ) );
  664. }
  665. }
  666. return "/adminExecute";
  667. }
  668. function delExecute() {
  669. $uid = isset ( $this->params ['uid'] ) && is_numeric ( $this->params ['uid'] ) ? $this->params ['uid'] : 0;
  670. $eid = isset ( $this->params ['eid'] ) && is_numeric ( $this->params ['eid'] ) ? $this->params ['eid'] : 0;
  671. if (! empty ( $uid ) && ! empty ( $eid )) {
  672. Doo::loadModel ( "execute" );
  673. $execute = new execute ();
  674. $executeInfo = $execute->getOne ( array (
  675. 'where' => 'eid ="' . $eid . '" ',
  676. 'asArray' => true
  677. ) );
  678. if (empty ( $executeInfo ))
  679. return "/adminExecute";
  680. $ini = array ();
  681. $list = json_decode ( $executeInfo ['staff'], true );
  682. foreach ( $list as $k => $v ) {
  683. if ($v [0] == $uid) {
  684. $ini = $list [$k];
  685. unset ( $list [$k] );
  686. break;
  687. }
  688. }
  689. file_put_contents ( "protected/config/execute/execute.ini", "," . $ini [0], FILE_APPEND );
  690. $execute->staff = json_encode ( $list );
  691. $execute->update ( array (
  692. 'where' => 'eid = ' . $executeInfo ['eid']
  693. ) );
  694. }
  695. return "/adminExecute";
  696. }
  697. function adminInvoice() {
  698. Doo::loadModel ( 'staff' );
  699. $staff = new staff ();
  700. Doo::loadModel ( "invoiceManage" );
  701. $invoiceManage = new invoiceManage ();
  702. $data ['staffList'] = $staff->find ( array (
  703. 'select' => 'username,sid,avatar',
  704. 'asArray' => true
  705. ) );
  706. $list = $invoiceManage->find ( array (
  707. 'asArray' => true
  708. ) );
  709. $execute = array (
  710. '收款管理' => '',
  711. '发票审批' => '',
  712. '发票打印' => '',
  713. '发票邮寄' => '',
  714. '发票退票' => '',
  715. '公司汇总查阅' => ''
  716. );
  717. foreach ( $list as $key => $value ) {
  718. $name = json_decode ( $value ['staff'] );
  719. $staffString = "";
  720. if (! empty ( $name )) {
  721. foreach ( $name as $k => $v ) {
  722. $staffString .= "<span class='tagGroup'> " . $v [1] . '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/delInvoiceManage/' . $v [0] . '/' . $value ['iid'] . '\'" title="删除" class="icon-">k</a></span>';
  723. }
  724. }
  725. foreach ( $execute as $k => $v ) {
  726. if ($k == $value ['mold']) {
  727. $execute [$k] = $name = $staffString;
  728. }
  729. }
  730. }
  731. $data ['invoice'] = $execute;
  732. $data ['memu'] = "invoice";
  733. $data ['staff'] = $this->staff;
  734. $this->render ( "/admin/adminInvoice", $data );
  735. }
  736. function addInvoiceManage() {
  737. $mold = $this->get_args ( 'mold' ) ? $this->get_args ( 'mold' ) : "";
  738. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  739. if (! empty ( $mold ) && ! empty ( $staff )) {
  740. Doo::loadModel ( "invoiceManage" );
  741. $execute = new invoiceManage ();
  742. $executeInfo = $execute->getOne ( array (
  743. 'where' => 'mold ="' . $mold . '" ',
  744. 'asArray' => true
  745. ) );
  746. if (empty ( $executeInfo )) {
  747. $list = array ();
  748. foreach ( $staff as $key => $value ) {
  749. $info = explode ( ":", $value );
  750. array_push ( $list, $info );
  751. }
  752. $execute->mold = $mold;
  753. $execute->staff = json_encode ( $list );
  754. $execute->insert ();
  755. } else {
  756. $list = json_decode ( $executeInfo ['staff'], true );
  757. foreach ( $staff as $k => $v ) {
  758. $info = explode ( ":", $v );
  759. foreach ( $list as $key => $value ) {
  760. if ($value [1] == $info [1]) {
  761. unset ( $staff [$k] );
  762. break;
  763. }
  764. }
  765. }
  766. foreach ( $staff as $k => $v ) {
  767. $info = explode ( ":", $v );
  768. array_push ( $list, $info );
  769. }
  770. $execute->staff = json_encode ( $list );
  771. $execute->update ( array (
  772. 'where' => 'iid = ' . $executeInfo ['iid']
  773. ) );
  774. }
  775. }
  776. return "/adminInvoice";
  777. }
  778. /**
  779. * 发票相关权限配置,把相关组的审批人删除。不会影响已经生成发票数据,修改后只会影响修改后生成的发票数据
  780. * @return string 返回配置页
  781. */
  782. function delInvoiceManage() {
  783. $uid = isset ( $this->params ['uid'] ) && is_numeric ( $this->params ['uid'] ) ? $this->params ['uid'] : 0;
  784. $iid = isset ( $this->params ['iid'] ) && is_numeric ( $this->params ['iid'] ) ? $this->params ['iid'] : 0;
  785. if (! empty ( $uid ) && ! empty ( $iid )) {
  786. Doo::loadModel ( "invoiceManage" );
  787. $execute = new invoiceManage ();
  788. $executeInfo = $execute->getOne ( array (
  789. 'where' => 'iid ="' . $iid . '" ',
  790. 'asArray' => true
  791. ) );
  792. if (empty ( $executeInfo ))
  793. return "/adminInvoice";
  794. $ini = array ();
  795. $list = json_decode ( $executeInfo ['staff'], true );
  796. foreach ( $list as $k => $v ) {
  797. if ($v [0] == $uid) {
  798. $ini = $list [$k];
  799. unset ( $list [$k] );
  800. break;
  801. }
  802. }
  803. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  804. if (! empty ( $fileInvoice )) {
  805. $fileInvoice = json_decode ( $fileInvoice, true );
  806. if (isset ( $fileInvoice [$executeInfo ['mold']] ))
  807. $fileInvoice [$executeInfo ['mold']] .= "," . $ini [0];
  808. else
  809. $fileInvoice [$executeInfo ['mold']] = '';
  810. $moldArray = explode ( ',', $fileInvoice [$executeInfo ['mold']] );
  811. $moldArray = array_unique ( $moldArray );
  812. $fileInvoice [$executeInfo ['mold']] = implode ( ',', $moldArray );
  813. $fileInvoice = json_encode ( $fileInvoice );
  814. file_put_contents ( "protected/config/invoice/invoice.ini", $fileInvoice );
  815. } else {
  816. $fileInvoice = array (
  817. $executeInfo ['mold'] => $ini [0]
  818. );
  819. $fileInvoice = json_encode ( $fileInvoice );
  820. file_put_contents ( "protected/config/invoice/invoice.ini", $fileInvoice );
  821. }
  822. file_put_contents ( "protected/config/execute/invoice.ini", "," . $ini [0], FILE_APPEND );
  823. $execute->staff = json_encode ( $list );
  824. $execute->update ( array (
  825. 'where' => 'iid = ' . $executeInfo ['iid']
  826. ) );
  827. }
  828. return "/adminInvoice";
  829. }
  830. function ajaxRoleStaff() {
  831. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  832. Doo::loadModel ( 'staff' );
  833. $staff = new staff ();
  834. $staffList = $staff->find ( array (
  835. 'select' => 'username,sid,avatar',
  836. 'where' => 'username != "' . $name . '" and username !="admin"',
  837. 'asArray' => true
  838. ) );
  839. $html = '';
  840. foreach ( $staffList as $key => $value ) {
  841. $html .= '<option value=' . $value ['sid'] . '_' . $value ['username'] . '>' . $value ['username'] . '</option>';
  842. }
  843. echo json_encode ( array (
  844. "success" => true,
  845. 'html' => $html
  846. ) );
  847. die ();
  848. }
  849. function loadCVS() {
  850. Doo::loadModel ( 'longle' );
  851. $longle = new longle ();
  852. $list = $longle->find ( array (
  853. 'select' => 'key_num',
  854. 'asArray' => TRUE
  855. ) );
  856. $file = fopen ( DOO::conf ()->SITE_PATH . "upload/key2.csv", 'r' );
  857. while ( $data = fgetcsv ( $file ) ) {
  858. $goods_list [$data [0]] = $data [1];
  859. }
  860. fclose ( $file );
  861. $sqlArray = array ();
  862. $sql = 'UPDATE CLD_longle SET SerialNumber = CASE key_num ';
  863. foreach ( $list as $key => $value ) {
  864. if (array_key_exists ( $value ['key_num'], $goods_list )) {
  865. // echo $value['key_num'].'-'.$goods_list[$value['key_num']].'<br/>';
  866. // $longle->SerialNumber=$goods_list[$value['key_num']];
  867. // $longle->update(array('where'=>'key_num="'.$value['key_num'].'"'));
  868. $sql .= ' WHEN "' . $value ['key_num'] . '" THEN "' . $goods_list [$value ['key_num']] . '" ';
  869. array_push ( $sqlArray, '"' . $value ['key_num'] . '"' );
  870. unset ( $goods_list [$value ['key_num']] );
  871. }
  872. }
  873. $sql .= 'END WHERE key_num IN (' . implode ( ',', $sqlArray ) . ')';
  874. echo $sql . '<br/>--------------------------------<br/>';
  875. foreach ( $goods_list as $key => $value ) {
  876. echo $key . ',' . $value . '<br/>';
  877. }
  878. }
  879. private function getRandChar($length) {
  880. $str = null;
  881. $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
  882. $max = strlen ( $strPol ) - 1;
  883. for($i = 0; $i < $length; $i ++) {
  884. $str .= $strPol [rand ( 0, $max )]; // rand($min,$max)生成介于min和max两个数之间的一个随机整数
  885. }
  886. return $str;
  887. }
  888. private function getReceiptCount() {
  889. $status = 2;
  890. $year = date ( 'Y' );
  891. Doo::loadModel ( 'receipt' );
  892. $receipt = new receipt ();
  893. Doo::loadModel ( 'verify' );
  894. $verify = new verify ();
  895. // user verify ID
  896. $vidList = array ();
  897. $verifyDetail = $verify->find ( array (
  898. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '\"%"',
  899. 'asArray' => true
  900. ) );
  901. foreach ( $verifyDetail as $key => $value ) {
  902. array_push ( $vidList, $value ['vid'] );
  903. }
  904. $vid = implode ( ",", $vidList );
  905. if (empty ( $verifyDetail ))
  906. $vid = 0;
  907. $dateCondition = " and Year(date) =" . $year;
  908. $approvalCondition = ' and verifyStaff not like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  909. $receiptList = $receipt->find ( array (
  910. 'where' => 'verify in(' . $vid . ') and status=' . $status . $dateCondition . $approvalCondition,
  911. 'desc' => 'rid',
  912. 'asArray' => true
  913. ) );
  914. return count ( $receiptList );
  915. }
  916. /**
  917. * 格式化excel文件为数组
  918. * @param unknown_type $file_url
  919. * @param unknown_type $mcid
  920. */
  921. function _format_excel_to_array($file_url = "") {
  922. if (! file_exists ( $file_url ))
  923. return array ();
  924. Doo::loadClass ( 'PHPExcel' );
  925. $PHPExcel = new PHPExcel ();
  926. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  927. if (! $PHPReader->canRead ( $file_url )) {
  928. $PHPReader = new PHPExcel_Reader_Excel5 ();
  929. if (! $PHPReader->canRead ( $file_url )) {
  930. echo 'no Excel';
  931. return;
  932. }
  933. }
  934. $PHPExcel = $PHPReader->load ( $file_url );
  935. /**
  936. * 读取excel文件中的第一个工作表
  937. */
  938. $currentSheet = $PHPExcel->getSheet ( 0 );
  939. /**
  940. * 取得最大的列号
  941. */
  942. $allColumn = $currentSheet->getHighestColumn ();
  943. /**
  944. * 取得一共有多少行
  945. */
  946. $allRow = $currentSheet->getHighestRow ();
  947. $excel_array = array ();
  948. for($currentRow = 2; $currentRow <= $allRow; $currentRow ++) {
  949. $excel_column = array ();
  950. // 后期改进
  951. if ($allColumn == 'AM')
  952. $allColumn = 'Z';
  953. /**
  954. * 从第A列开始输出
  955. */
  956. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  957. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  958. /**
  959. * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312',
  960. */
  961. $val = "'" . addslashes ( $val ) . "'";
  962. if ($currentColumn == 'A')
  963. $excel_column ['key_num'] = $val;
  964. elseif ($currentColumn == 'C')
  965. $excel_column ['product'] = $val;
  966. elseif ($currentColumn == 'D') {
  967. $val = str_replace ( "'", "", $val );
  968. $excel_column ['make_day'] = $this->excelTime ( $val );
  969. } elseif ($currentColumn == 'E') {
  970. $val = str_replace ( "'", "", $val );
  971. $excel_column ['alloted_time'] = $this->excelTime ( $val );
  972. } elseif ($currentColumn == 'F') {
  973. $val = str_replace ( "'", "", $val );
  974. $excel_column ['version'] = $val;
  975. } elseif ($currentColumn == 'B') {
  976. $val = str_replace ( "'", "", $val );
  977. $excel_column ['SerialNumber'] = $val;
  978. }
  979. }
  980. array_push ( $excel_array, $excel_column );
  981. }
  982. return $excel_array;
  983. }
  984. function excelTime($date, $time = false) {
  985. if (function_exists ( 'GregorianToJD' )) {
  986. if (is_numeric ( $date )) {
  987. $jd = GregorianToJD ( 1, 1, 1970 );
  988. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  989. $date = explode ( '/', $gregorian );
  990. $date_str = str_pad ( $date [2], 4, '0', STR_PAD_LEFT ) . "-" . str_pad ( $date [0], 2, '0', STR_PAD_LEFT ) . "-" . str_pad ( $date [1], 2, '0', STR_PAD_LEFT ) . ($time ? " 00:00:00" : '');
  991. return $date_str;
  992. }
  993. } else {
  994. $date = $date > 25568 ? $date + 1 : 25569;
  995. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  996. $ofs = (70 * 365 + 17 + 2) * 86400;
  997. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  998. }
  999. return $date;
  1000. }
  1001. function _GetFileEXT($filename) {
  1002. $pics = explode ( '.', $filename );
  1003. $num = count ( $pics );
  1004. return $pics [$num - 1];
  1005. }
  1006. /**
  1007. * 获取get或者POST值
  1008. * @param string $name 属性名称
  1009. * @return fixed 值
  1010. */
  1011. function get_args($name) {
  1012. if (isset ( $_GET [$name] )) {
  1013. if (is_array ( $_GET [$name] ))
  1014. return $_GET [$name];
  1015. else {
  1016. return addslashes ( $_GET [$name] );
  1017. // return $_GET [$name] ;
  1018. }
  1019. } elseif (isset ( $_POST [$name] )) {
  1020. if (is_array ( $_POST [$name] ))
  1021. return $_POST [$name];
  1022. else {
  1023. return addslashes ( $_POST [$name] );
  1024. // return $_POST [$name];
  1025. }
  1026. } else {
  1027. return false;
  1028. }
  1029. }
  1030. function get_previous($on_page = 1) {
  1031. return $on_page != 0 ? $on_page - 1 : $on_page;
  1032. }
  1033. /**
  1034. * 获得分页数据
  1035. * @param unknown_type $table
  1036. * @param unknown_type $condition
  1037. * @param unknown_type $on_page
  1038. * @param unknown_type $page_size
  1039. */
  1040. function get_Tpage($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $tagSQL) {
  1041. $page_c = "";
  1042. $page ['previous'] = $this->get_previous ( $on_page );
  1043. $page ['on_page'] = $on_page;
  1044. $total_count = $this->get_table_Tcount ( $table, $condition, $tagSQL );
  1045. $total = intval ( $total_count / $page_size );
  1046. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  1047. $page ['total_data'] = $total_count;
  1048. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  1049. $i = 1;
  1050. $page_max = 1;
  1051. if ($on_page > 10) {
  1052. $page_max = intval ( $on_page / 10 ) + 1;
  1053. $i = intval ( $on_page / 10 ) * 10 - 1;
  1054. }
  1055. $page ['page'] = $page_c;
  1056. $page ['lower'] = (-- $on_page) * $page_size;
  1057. return $page;
  1058. }
  1059. /**
  1060. * 获得分页数据
  1061. * @param unknown_type $table
  1062. * @param unknown_type $condition
  1063. * @param unknown_type $on_page
  1064. * @param unknown_type $page_size
  1065. */
  1066. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page", $staffid = "", $search, $tooltip, $cateid, $tagSQL) {
  1067. $page_c = "";
  1068. $page ['previous'] = $this->get_previous ( $on_page );
  1069. $page ['on_page'] = $on_page;
  1070. $total_count = $this->get_table_count ( $table, $condition, $staffid, $search, $tooltip, $cateid, $tagSQL );
  1071. $total = intval ( $total_count / $page_size );
  1072. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  1073. $page ['total_data'] = $total_count;
  1074. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  1075. $i = 1;
  1076. $page_max = 1;
  1077. if ($on_page > 10) {
  1078. $page_max = intval ( $on_page / 10 ) + 1;
  1079. $i = intval ( $on_page / 10 ) * 10 - 1;
  1080. }
  1081. for(; $i <= $page ['total_page']; $i ++) {
  1082. if ($i == $on_page) {
  1083. if ($other == "page")
  1084. $page_c .= '<a href="javascript:void(0);" class="current">' . $i . '</a>';
  1085. else
  1086. $page_c .= '&nbsp;<span class="current">' . $i . '</span>&nbsp;';
  1087. } else if ($other == "page")
  1088. $page_c .= '<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>';
  1089. else
  1090. $page_c .= '&nbsp;<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>&nbsp;';
  1091. if ($i == (10 * $page_max))
  1092. break;
  1093. }
  1094. $page ['page'] = $page_c;
  1095. $page ['lower'] = (-- $on_page) * $page_size;
  1096. return $page;
  1097. }
  1098. /**
  1099. * 获取总页数
  1100. * @param unknown_type $table
  1101. * @param unknown_type $condition
  1102. */
  1103. public function get_table_Tcount($table = "", $condition = "", $tagSQL) {
  1104. if ($tagSQL)
  1105. $sql = "select count(*) as count from CLD_tagCompanyNexus as a left join CLD_company as b on (a.company=b.cid ) where " . $condition;
  1106. else
  1107. $sql = "select count(*) as count from CLD_company where " . $condition;
  1108. $query = Doo::db ()->query ( $sql );
  1109. $result = $query->fetch ();
  1110. return $result ['count'];
  1111. }
  1112. /**
  1113. * 获取总页数
  1114. * @param unknown_type $table
  1115. * @param unknown_type $condition
  1116. */
  1117. public function get_table_count($table = "", $condition = "", $staffid = "", $search, $tooltip, $cateid, $tagSQL) {
  1118. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  1119. // echo $staffid;die;
  1120. //
  1121. if (! empty ( $staffid )) {
  1122. // $staffid="and a.sid= '".$staffid."'"; " . $table . " as a left join on (a.cid=b.cid ".$staffid.")
  1123. $sql = "select count(*) as count from CLD_client as b left join CLD_tag_client as c on (b.cid=c.client) where 1 " . $condition;
  1124. } else {
  1125. if (strlen ( $condition ) == 1 || empty ( $condition ))
  1126. $sql = "select count(*) as count from CLD_client as a " . $condition;
  1127. else
  1128. $sql = "select count(*) as count from CLD_client as a left join CLD_tag_client as c on (a.cid=c.client) where 1 " . $condition;
  1129. }
  1130. if (! empty ( $search ))
  1131. $sql = "select count(*) as count from CLD_client as a where 1 " . $condition;
  1132. if (! empty ( $tooltip )) {
  1133. $condition = str_replace ( "a.", "c.", $condition );
  1134. if ($tagSQL)
  1135. $sql = "select count(*) as count from CLD_C_tooltip as a left join CLD_tag_client as c on (a.cid=c.client) left join CLD_client as b on (c.client=b.cid ) where a.name like '%" . $tooltip . "%' and a.cateid = " . $cateid . " " . $condition;
  1136. else
  1137. $sql = "select count(*) as count from CLD_C_tooltip as a left join CLD_client as b on (a.cid=b.cid ) where a.name like '%" . $tooltip . "%' and a.cateid = " . $cateid . " " . $condition;
  1138. }
  1139. // echo $sql;
  1140. $query = Doo::db ()->query ( $sql );
  1141. $result = $query->fetch ();
  1142. return $result ['count'];
  1143. }
  1144. public function holidayGroup(){
  1145. Doo::loadModel('staff');
  1146. Doo::loadModel("holidayacman");
  1147. $acman=new HACMan();
  1148. $staff=new staff();
  1149. $data['staffList']=$staff->find(array('select'=>'username,sid,wxid', 'where' => 'cid!=1','asArray'=>true));
  1150. $acmanlist=$acman->find(array('where' => 'type=0', 'desc' => 'id','asArray'=>true));
  1151. if(!empty($acmanlist)){
  1152. foreach($acmanlist as $k => $v){
  1153. $acmanlist[$k]['name'] = implode('->', explode(' ', $v['name']));
  1154. }
  1155. }
  1156. $data['acmanlist'] = $acmanlist;
  1157. $data['staff']=$this->staff;
  1158. $data['memu'] = 'holiday';
  1159. $data['noindexjs'] = 'noindexjs';
  1160. $this->render( "/admin/admin_holidayGroup", $data );
  1161. }
  1162. public function addHolidayApprover() {
  1163. if (! isset ( $_POST ['title'] ) || empty ( $_POST ['title'] )) {
  1164. exit ( '请输入组名' );
  1165. }
  1166. if (! isset ( $_POST ['staff'] ) || empty ( $_POST ['staff'] )) {
  1167. exit ( '请选择成员' );
  1168. }
  1169. $idname = $name = $pinyinname = array ();
  1170. $stafflist = explode(',',$_POST['staff']);
  1171. foreach ( $stafflist as $k => $v ) {
  1172. $msg = explode ( ':', $v );
  1173. array_push ( $idname, $msg [0] );
  1174. array_push ( $name, $msg [1] );
  1175. array_push ( $pinyinname, $msg [2] );
  1176. }
  1177. Doo::loadModel("holidayacman");
  1178. $acman=new HACMan();
  1179. $acman->typename = $_POST['title'];
  1180. $acman->idname = implode(',', $idname);
  1181. $acman->name = implode(' ', $name);
  1182. $acman->pinyinname = implode('|', $pinyinname);
  1183. $acman->type = 0;
  1184. $result = $acman->insert();
  1185. if($result){
  1186. $acman2=new HACMan();
  1187. $acman2->type = $result;
  1188. $acman2->insert();
  1189. Doo::loadModel('holidaystaff');
  1190. foreach($idname as $ik => $iv){
  1191. $hstaff = new HStaff();
  1192. $hstaff->uid = $iv;
  1193. $hstaff->isadmin = 1;
  1194. $hstaff->update();
  1195. }
  1196. }
  1197. return '/holidaygroup';
  1198. }
  1199. public function delHolidayGroup(){
  1200. if(!isset($_POST['approvalid']) || empty($_POST['approvalid']) || !is_numeric($_POST['approvalid'])){
  1201. exit('审批组id出错');
  1202. }
  1203. Doo::loadModel('holidayacman');
  1204. $acman = new HACMan();
  1205. $idname = $acman->getOne(array('where' => 'id='.$_POST['approvalid'], 'asArray' => TRUE));
  1206. $idname = explode(',', $idname['idname']);
  1207. $acman->id = $_POST['approvalid'];
  1208. $acman->delete();
  1209. // $acman2 = new HACMan();
  1210. // $acman2->type = $_POST['approvalid'];
  1211. // $acman2->delete();
  1212. //删除管理员资格
  1213. $acman3 = new HACMan();
  1214. foreach($idname as $k => $v){
  1215. $same = 0;
  1216. $approverlist = $acman3->find(array('where' => 'idname like "%'.$v.'%" and type=0', 'asArray' => TRUE));
  1217. if(!empty($approverlist)){
  1218. foreach($approverlist as $ak => $av){
  1219. $aidname = explode(',', $av['idname']);
  1220. foreach($aidname as $ik => $iv){
  1221. if($iv == $v){
  1222. $same = 1;
  1223. break;
  1224. }
  1225. }
  1226. }
  1227. }
  1228. if($same == 0){
  1229. Doo::loadModel('holidaystaff');
  1230. $hstaff = new HStaff();
  1231. $hstaff->uid = $v;
  1232. $hstaff->isadmin = 0;
  1233. $hstaff->update();
  1234. }
  1235. }
  1236. return '/holidaygroup';
  1237. }
  1238. public function holidayCSGroup(){
  1239. Doo::loadModel('staff');
  1240. Doo::loadModel('holidayacman');
  1241. $acman = new HACMan();
  1242. $staff = new staff();
  1243. $approverlist = $acman->find(array('where' => 'type=0', 'desc' => 'id', 'asArray' => TRUE));
  1244. if(!empty($approverlist)){
  1245. foreach($approverlist as $k => $v){
  1246. $csman = $acman->getOne(array('where' => 'type='.$v['id'], 'asArray' => TRUE));
  1247. if(!empty($csman['name'])){
  1248. $idname = explode(',',$csman['idname']);
  1249. $name = explode(' ',$csman['name']);
  1250. $pinyinname = explode('|',$csman['pinyinname']);
  1251. $csmsg = array();
  1252. foreach($idname as $ik => $iv){
  1253. $csmsg[$ik]['csidname'] = $iv;
  1254. $csmsg[$ik]['csname'] = $name[$ik];
  1255. $csmsg[$ik]['cspinyinname'] = $pinyinname[$ik];
  1256. }
  1257. $approverlist[$k]['csmsg'] = $csmsg;
  1258. }
  1259. }
  1260. $data['approverlist'] = $approverlist;
  1261. }
  1262. //获取总部人员列表
  1263. $zongbu = $staff->getStaffByCid(12);
  1264. $data['zongbu'] = $zongbu;
  1265. //获取办事处列表
  1266. Doo::loadModel('L_category');
  1267. $L_category = new L_category();
  1268. $data['category']=$L_category->getCategory();
  1269. $data['memu'] = 'holiday';
  1270. $data['noindexjs'] = 'noindexjs';
  1271. $this->render( "/admin/admin_holidayGroup_cc", $data );
  1272. }
  1273. public function getStaffCategory(){
  1274. if(isset($_POST['cid']) && is_numeric($_POST['cid'])){
  1275. Doo::loadModel('staff');
  1276. $staff = new staff();
  1277. $stafflist = $staff->getStaffByCid($_POST['cid']);
  1278. exit(json_encode(array('code' => 200, 'stafflist' => $stafflist)));
  1279. }
  1280. exit(json_encode(array('code' => 400)));
  1281. }
  1282. public function addHolidayCS(){
  1283. if(!isset($_POST['approvalid']) || empty($_POST['approvalid']) || !is_numeric($_POST['approvalid'])){
  1284. exit('审批组出错');
  1285. }
  1286. if(!isset($_POST['cidstaff']) || empty($_POST['cidstaff'])){
  1287. exit('抄送人出错');
  1288. }
  1289. $cidstaff = explode(':',$_POST['cidstaff']);
  1290. Doo::loadModel('holidayacman');
  1291. $acman = new HACMan();
  1292. $csmsg = $acman->getOne(array('where' => 'type='.$_POST['approvalid'], 'asArray' => TRUE));
  1293. $csidmsg = !empty($csmsg['idname']) ? $csmsg['idname'].','.$cidstaff[0] : $cidstaff[0];
  1294. $csnamemsg = !empty($csmsg['name']) ? $csmsg['name'].' '.$cidstaff[1] : $cidstaff[1];
  1295. $cspinyinnamemsg = !empty($csmsg['pinyinname']) ? $csmsg['pinyinname'].'|'.$cidstaff[2] : $cidstaff[2];
  1296. $acman->id = $csmsg['id'];
  1297. $acman->idname = $csidmsg;
  1298. $acman->name = $csnamemsg;
  1299. $acman->pinyinname = $cspinyinnamemsg;
  1300. $acman->update();
  1301. return '/hcsgroup';
  1302. }
  1303. public function delHolidayCS(){
  1304. if(!isset($_POST['approvalid']) || empty($_POST['approvalid']) || !is_numeric($_POST['approvalid'])){
  1305. exit('审批id出错');
  1306. }
  1307. if(!isset($_POST['cidstaff']) || empty($_POST['cidstaff'])){
  1308. exit('抄送信息出错');
  1309. }
  1310. $cidstaff = explode(':',$_POST['cidstaff']);
  1311. Doo::loadModel('holidayacman');
  1312. $acman = new HACMan();
  1313. $csmsg = $acman->getOne(array('where' => 'type='.$_POST['approvalid'], 'asArray' => TRUE));
  1314. if(!empty($csmsg['idname'])){
  1315. $idnamearr = explode(',', $csmsg['idname']);
  1316. foreach($idnamearr as $ik => $iv){
  1317. if($iv == $cidstaff[0]){
  1318. unset($idnamearr[$ik]);
  1319. break;
  1320. }
  1321. }
  1322. $csidmsg = implode(',',$idnamearr);
  1323. }
  1324. if(!empty($csmsg['name'])){
  1325. $namearr = explode(' ', $csmsg['name']);
  1326. foreach($namearr as $nk => $nv){
  1327. if($nv == $cidstaff[1]){
  1328. unset($namearr[$nk]);
  1329. break;
  1330. }
  1331. }
  1332. $csnamemsg = implode(' ',$namearr);
  1333. }
  1334. if(!empty($csmsg['pinyinname'])){
  1335. $pinyinnamearr = explode('|', $csmsg['pinyinname']);
  1336. foreach($pinyinnamearr as $pk => $pv){
  1337. if($pv == $cidstaff[2]){
  1338. unset($pinyinnamearr[$pk]);
  1339. break;
  1340. }
  1341. }
  1342. $cspinyinnamemsg = implode('|',$pinyinnamearr);
  1343. }
  1344. $acman->id = $csmsg['id'];
  1345. if(isset($csidmsg)){
  1346. $acman->idname = $csidmsg;
  1347. }
  1348. if(isset($csnamemsg)){
  1349. $acman->name = $csnamemsg;
  1350. }
  1351. if(isset($cspinyinnamemsg)){
  1352. $acman->pinyinname = $cspinyinnamemsg;
  1353. }
  1354. $acman->update();
  1355. return '/hcsgroup';
  1356. }
  1357. public function HolidayAdmin(){
  1358. Doo::loadModel('staff');
  1359. $staff=new staff();
  1360. $staffList=$staff->find(array('select'=>'username,sid', 'where' => 'cid!=1','asArray'=>true));
  1361. Doo::loadModel('holidayadmin');
  1362. $admin = new HAdmin();
  1363. $adminList = $admin->find(array('asArray' => TRUE));
  1364. if(!empty($adminList)){
  1365. foreach($adminList as $k => $v){
  1366. foreach($staffList as $sk => $sv){
  1367. if($sv['sid'] == $v['uid']){
  1368. array_splice($staffList, $sk,1);
  1369. break;
  1370. }
  1371. }
  1372. }
  1373. }
  1374. $data['staffList'] = $staffList;
  1375. $data['adminList'] = $adminList;
  1376. $data['memu'] = 'holiday';
  1377. $data['noindexjs'] = 'noindexjs';
  1378. $this->render( "/admin/admin_holidayuser", $data );
  1379. }
  1380. public function addHolidayAdmin(){
  1381. if(!isset($_POST['staff']) || empty($_POST['staff'])){
  1382. exit('请选择管理人');
  1383. }
  1384. Doo::loadModel('holidayadmin');
  1385. foreach($_POST['staff'] as $k => $v){
  1386. $staffmsg = explode(':',$v);
  1387. $admin = new HAdmin();
  1388. $admin->uid = $staffmsg[0];
  1389. $admin->username = $staffmsg[1];
  1390. $admin->insert();
  1391. }
  1392. return '/holidayadmin';
  1393. }
  1394. public function delHolidayAdmin(){
  1395. if(!isset($_POST['cidstaff']) || empty($_POST['cidstaff'])){
  1396. exit('请选择管理人删除');
  1397. }
  1398. Doo::loadModel('holidayadmin');
  1399. $admin = new HAdmin();
  1400. $admin->id = $_POST['cidstaff'];
  1401. $admin->delete();
  1402. return '/holidayadmin';
  1403. }
  1404. //检查年假是否过期并更新年假
  1405. private function updateAnnualLeave($staff){
  1406. Doo::loadModel('holidaystaff');
  1407. $hstaff = new HStaff();
  1408. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$staff['sid'],'asArray' => TRUE));
  1409. $hiredate = $staff['hiredate'];
  1410. if(intval((time()-strtotime($hiredate))/(86400*365)) != $hstaffmsg['hadyear'] && $staff['nature'] == 1 ){
  1411. $hstaff->uid = $staff['sid'];
  1412. $hstaff->hadyear = intval((time()-strtotime($hiredate))/(86400*365));
  1413. $hstaff->yearnum = intval((time()-strtotime($hiredate))/(86400*365)) != 0 ? 5 : 0;
  1414. $hstaff->update();
  1415. }
  1416. }
  1417. }
  1418. ?>