AdminController.php 40 KB

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