AdminController.php 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330
  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 = $this->get_args ( 'passwork' ) ? $this->get_args ( 'passwork' ) : "";
  76. $uid = $this->get_args ( 'user' ) ? $this->get_args ( 'user' ) : "";
  77. Doo::loadModel ( 'staff' );
  78. $staff = new staff ();
  79. Doo::loadClass ( 'XDeode' );
  80. $XDeode = new XDeode ( 5 );
  81. if (! empty ( $passwork )) {
  82. $userinfo = $staff->getOne ( array (
  83. 'where' => "username='admin'",
  84. 'asArray' => true
  85. ) );
  86. if (! empty ( $userinfo )) {
  87. if ($userinfo ['username'] == $uid && $userinfo ['passwork'] == md5 ( $passwork )) {
  88. setcookie ( "adStaff", $XDeode->encode ( $userinfo ['sid'] ), time () + 36000, "/" );
  89. return "/adminoffice";
  90. }
  91. }
  92. }
  93. $data ['staff'] = "";
  94. $data ['login'] = "";
  95. if (! empty ( $passwork ))
  96. $data ['login'] = "inputErrow";
  97. $this->render ( "/admin/adminLogin", $data );
  98. }
  99. function adout() {
  100. setcookie ( "adStaff", "", time () - 3600, "/" );
  101. return "/adlogin";
  102. }
  103. function adminPW() {
  104. $msg = $this->params ['msg'] ? $this->params ['msg'] : "";
  105. $data ['msg'] = "msg";
  106. $data ['memu'] = "adminpw";
  107. $data ['staff'] = $this->staff;
  108. $data ['msg'] = urldecode ( $this->params ['msg'] );
  109. $this->render ( "/admin/admin-admininfo", $data );
  110. }
  111. function upAdP() {
  112. $opw = $this->get_args ( 'opw' ) ? $this->get_args ( 'opw' ) : "";
  113. $npw1 = $this->get_args ( 'npw1' ) ? $this->get_args ( 'npw1' ) : "";
  114. $npw2 = $this->get_args ( 'npw2' ) ? $this->get_args ( 'npw2' ) : "";
  115. if (! empty ( $opw )) {
  116. Doo::loadModel ( 'staff' );
  117. $staff = new staff ();
  118. $userinfo = $staff->getOne ( array (
  119. 'where' => "username='admin'",
  120. 'asArray' => true
  121. ) );
  122. if (! empty ( $userinfo )) {
  123. if ($userinfo ['sid'] == $_COOKIE ["adStaff"] && $userinfo ['passwork'] == md5 ( $opw )) {
  124. if (($npw1 == $npw2) && ($npw1 != "")) {
  125. $staff->passwork = md5 ( $npw1 );
  126. $staff->update ( array (
  127. 'where' => "sid='" . $_COOKIE ["adStaff"] . "'"
  128. ) );
  129. return "/adminpw/" . urlencode ( '密码修改成功' );
  130. } else
  131. return "/adminpw/" . urlencode ( '新密码不一致' );
  132. } else
  133. return "/adminpw/" . urlencode ( '旧密码不正确' );
  134. } else
  135. return "/adminpw/" . urlencode ( '未找到用户' );
  136. } else
  137. return "/adminpw/" . urlencode ( '请输入旧密码' );
  138. }
  139. function adminoffice() {
  140. $data ['memu'] = "adminoffice";
  141. $data ['staff'] = $this->staff;
  142. Doo::loadModel ( 'L_category' );
  143. Doo::loadModel ( 'staff' );
  144. Doo::loadModel ( 'district' );
  145. $district = new district ();
  146. $staff = new staff ();
  147. $L_category = new L_category ();
  148. $data ['category'] = $L_category->getCategory ();
  149. $data ['district'] = $district->get_lv ( 1 );
  150. foreach ( $data ['category'] as $key => $value ) {
  151. $data ['category'] [$key] ['count'] = $staff->count ( array (
  152. 'where' => 'cid=' . $value ['cid']
  153. ) );
  154. }
  155. $data ['msg'] = urldecode ( $this->params ['msg'] );
  156. $this->render ( "/admin/admin_group", $data );
  157. }
  158. function addCategory() {
  159. $msg = "添加成功";
  160. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  161. $district = $this->get_args ( 'district' ) ? $this->get_args ( 'district' ) : "";
  162. if (! empty ( $title ) && ! empty ( $district )) {
  163. Doo::loadModel ( 'L_category' );
  164. $L_category = new L_category ();
  165. $L_category->title = $title;
  166. $L_category->districtid = $district;
  167. $L_category->insert ();
  168. } else {
  169. $msg = "请输入正确的信息";
  170. }
  171. return "/adminoffice/" . $msg;
  172. }
  173. function adminuser() {
  174. $data ['memu'] = "adminuser";
  175. $data ['staff'] = $this->staff;
  176. Doo::loadModel ( 'L_category' );
  177. Doo::loadModel ( 'staff' );
  178. $staff = new staff ();
  179. $L_category = new L_category ();
  180. Doo::loadModel('district');
  181. $district=new district();
  182. Doo::loadClass ( 'XDeode' );
  183. $XDeode = new XDeode ( 5 );
  184. $stafflist=$staff->getStaff ();
  185. foreach ($stafflist as $key=>$value){
  186. $info=$staff->getUserById ( $value['sid'] );
  187. $didList=explode(',', $info[0]['did']);
  188. $didList=array_filter($didList);
  189. $list=array();
  190. if (!empty($didList)){
  191. foreach ($didList as $k=>$v){
  192. array_push($list, $XDeode->decode ( $v )) ;
  193. }
  194. $stafflist[$key]['idDistrictList']=$district->getDistrictInId(implode(',', $list));
  195. }else{
  196. $stafflist[$key]['idDistrictList']=array();
  197. }
  198. }
  199. $data['districtList']=$district->get_lv(1);
  200. $data ['category'] = $L_category->getCategory ();
  201. $data ['stafflist'] = $stafflist;
  202. $data ['staff'] = $this->staff;
  203. $this->render ( "/admin/admin_user", $data );
  204. }
  205. /**
  206. * 删除省份权限
  207. */
  208. function delUserDistrictAuthor(){
  209. $didKey = isset ( $this->params ['didKey'] ) ? $this->params ['didKey'] : "";
  210. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : "";
  211. if (! empty ( $sidKey ) && ! empty ( $didKey ) ) {
  212. Doo::loadClass ( 'XDeode' );
  213. $XDeode = new XDeode ( 5 );
  214. Doo::loadModel ( 'staff' );
  215. $staff = new staff ();
  216. $sid=$XDeode->decode($sidKey);
  217. $sDetail=$staff->getStaffBySid($sid);
  218. $sDidList=explode(',', $sDetail['did']);
  219. foreach ($sDidList as $key=>$value){
  220. if ($value==$didKey)
  221. unset($sDidList[$key]);
  222. }
  223. $staff->did=implode(',', $sDidList);
  224. $staff->sid = $sid;
  225. $staff->update ();
  226. return '/edi/user/'.$sid;
  227. }
  228. die ( 'illegal request' );
  229. }
  230. function adduser() {
  231. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  232. $password = $this->get_args ( 'password' ) ? $this->get_args ( 'password' ) : "";
  233. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  234. $hiredate = $this->get_args ( 'hiredate' ) ? $this->get_args ( 'hiredate' ) : "";
  235. $nature = is_numeric ( $this->get_args ( 'nature' ) ) ? $this->get_args ( 'nature' ) : 1;
  236. $didKey = $this->get_args ( 'didKey' ) ? $this->get_args ( 'didKey' ) : array();
  237. if (! empty ( $username ) && ! empty ( $password ) && ! empty ( $cid ) && ! empty ( $hiredate ) && ! empty ( $nature )) {
  238. Doo::loadModel ( 'L_category' );
  239. Doo::loadModel ( 'staff' );
  240. Doo::loadModel ( 'tag' );
  241. Doo::loadModel ( 'holidaystaff' );
  242. $staff = new staff ();
  243. $L_category = new L_category ();
  244. // 加入默认总部分类
  245. $cagegory = $L_category->getCategoryById ( $cid );
  246. // 根据这个分类加入管理权限
  247. if ($cagegory [0] ['defult'] == 1) {
  248. $staff->isadmin = 1;
  249. }
  250. $staff->username = $username;
  251. $staff->passwork = md5 ( $password );
  252. $staff->cid = $cagegory [0] ['cid'];
  253. $staff->category = $cagegory [0] ['title'];
  254. $staff->hiredate = $hiredate;
  255. $staff->nature = $nature;
  256. $staff->did=implode(',', $didKey);
  257. $id = $staff->insert ();
  258. $holidaystaff = new HStaff ();
  259. $holidaystaff->uid = $id;
  260. $holidaystaff->insert ();
  261. $staffmsg = $staff->getUserById ( $id );
  262. $this->updateAnnualLeave ( $staffmsg [0] );
  263. for($i = 1; $i <= 7; $i ++) {
  264. $tag = new tag ();
  265. $tag->name = "个人标签";
  266. $tag->sid = $id;
  267. $tag->colorid = $i;
  268. $tag->insert ();
  269. }
  270. }
  271. return "/adminuser";
  272. }
  273. function adminEdiUser() {
  274. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  275. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  276. if (! empty ( $sid )) {
  277. Doo::loadModel('district');
  278. $district=new district();
  279. $data ['msg'] = urldecode ( $msg );
  280. Doo::loadModel ( 'L_category' );
  281. $L_category = new L_category ();
  282. Doo::loadModel ( 'staff' );
  283. $staff = new staff ();
  284. Doo::loadClass ( 'XDeode' );
  285. $XDeode = new XDeode ( 5 );
  286. $info=$staff->getUserById ( $sid );
  287. $didList=explode(',', $info[0]['did']);
  288. $didList=array_filter($didList);
  289. $list=array();
  290. if (!empty($didList)){
  291. foreach ($didList as $key=>$value){
  292. array_push($list, $XDeode->decode ( $value )) ;
  293. }
  294. $idDistrictList=$district->getDistrictInId(implode(',', $list));
  295. }else{
  296. $idDistrictList=array();
  297. }
  298. $data['idDistrictList']=$idDistrictList;
  299. $data['districtList']=$district->get_lv(1);
  300. $data ['newPw'] = '';
  301. $data ['staffInfo'] = $info;
  302. $data ['category'] = $L_category->getCategory ();
  303. $data ['staff'] = $this->staff;
  304. $data ['memu'] = "adminuser";
  305. $this->render ( "/admin/admin_EdiUser", $data );
  306. } else
  307. return "/adminuser";
  308. }
  309. function adminResetUserPw() {
  310. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  311. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  312. if (! empty ( $sid )) {
  313. $data ['msg'] = urldecode ( $msg );
  314. Doo::loadModel ( 'L_category' );
  315. Doo::loadModel ( 'staff' );
  316. $staff = new staff ();
  317. $L_category = new L_category ();
  318. $newPw = $this->getRandChar ( 6 );
  319. $staff->sid = $sid;
  320. $staff->passwork = md5 ( $newPw );
  321. $staff->update ();
  322. $data ['newPw'] = $newPw;
  323. $data ['staffInfo'] = $staff->getUserById ( $sid );
  324. $data ['category'] = $L_category->getCategory ();
  325. $data ['staff'] = $this->staff;
  326. $data ['memu'] = "adminuser";
  327. $this->render ( "/admin/admin_EdiUser", $data );
  328. } else
  329. return "/adminuser";
  330. }
  331. function adminDoEdiUser() {
  332. $sid = is_numeric ( $this->get_args ( 'sid' ) ) ? $this->get_args ( 'sid' ) : 0;
  333. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  334. $gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "";
  335. $qq = is_numeric ( $this->get_args ( 'qq' ) ) ? $this->get_args ( 'qq' ) : 0;
  336. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  337. $telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : "";
  338. $email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
  339. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  340. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  341. $hiredate = $this->get_args ( 'hiredate' ) ? $this->get_args ( 'hiredate' ) : "";
  342. if (! empty ( $sid )) {
  343. $msg = "";
  344. Doo::loadModel ( 'L_category' );
  345. Doo::loadModel ( 'staff' );
  346. $staff = new staff ();
  347. $L_category = new L_category ();
  348. $categoryInfo = $L_category->getCategoryById ( $cid );
  349. $staff->sid = $sid;
  350. if ($cid != 0) {
  351. $staff->cid = $categoryInfo [0] ['cid'];
  352. $staff->category = $categoryInfo [0] ['title'];
  353. }
  354. if ($categoryInfo [0] ['defult'] == 1) {
  355. $staff->isadmin = 1;
  356. } else {
  357. $staff->isadmin = 0;
  358. }
  359. if (! empty ( $username ))
  360. $staff->username = $username;
  361. if (! empty ( $gender ))
  362. $staff->gender = $gender;
  363. if (! empty ( $qq ) && is_numeric ( $qq ))
  364. $staff->qq = $qq;
  365. if (! empty ( $phone ))
  366. $staff->phone = $phone;
  367. if (! empty ( $telephone ))
  368. $staff->telephone = $telephone;
  369. if (! empty ( $email ) && filter_var ( $email, FILTER_VALIDATE_EMAIL ))
  370. $staff->email = $email;
  371. else
  372. $msg = "邮箱不正确";
  373. if (! empty ( $hiredate ))
  374. $staff->hiredate = $hiredate;
  375. $staff->nature = $nature;
  376. $staff->update ();
  377. $staffmsg = $staff->getUserById ( $sid );
  378. $this->updateAnnualLeave ( $staffmsg [0] );
  379. return "/edi/user/" . $sid . "/" . $msg;
  380. } else {
  381. return "/adminuser";
  382. }
  383. }
  384. function adminDoAddCategory() {
  385. $sid = is_numeric ( $this->get_args ( 'sid' ) ) ? $this->get_args ( 'sid' ) : 0;
  386. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  387. if (! empty ( $sid )) {
  388. Doo::loadModel ( 'L_category' );
  389. Doo::loadModel ( 'staff' );
  390. $staff = new staff ();
  391. $L_category = new L_category ();
  392. $stfInfo = $staff->getOne ( array (
  393. 'where' => 'sid =' . $sid,
  394. 'asArray' => true
  395. ) );
  396. if ($stfInfo ['cid'] == $cid)
  397. return "/adminuser";
  398. $othcid = explode ( ',', $stfInfo ['othercid'] );
  399. if (in_array ( $cid, $othcid ))
  400. return "/adminuser";
  401. array_push ( $othcid, $cid );
  402. $strCid = implode ( ',', array_filter ( $othcid ) );
  403. $catename = $L_category->getCategoryById ( $cid );
  404. $othcategory = explode ( ',', $stfInfo ['othercategory'] );
  405. array_push ( $othcategory, $catename [0] ['title'] );
  406. $strcategory = implode ( ',', array_filter ( $othcategory ) );
  407. $staff->sid = $sid;
  408. $staff->othercid = $strCid;
  409. $staff->othercategory = $strcategory;
  410. $staff->update ();
  411. }
  412. return "/adminuser";
  413. }
  414. function adminDeleteUser() {
  415. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  416. if (! empty ( $sid )) {
  417. Doo::loadModel ( 'staff' );
  418. $staff = new staff ();
  419. $staff->sid = $sid;
  420. $staff->delete ();
  421. Doo::loadModel ( 'holidaystaff' );
  422. $hstaff = new HStaff ();
  423. $hstaff->uid = $sid;
  424. $hstaff->delete ();
  425. }
  426. return "/adminuser";
  427. }
  428. function adminproduct() {
  429. $data ['memu'] = "adminproduct";
  430. $data ['staff'] = $this->staff;
  431. Doo::loadModel ( 'product' );
  432. Doo::loadModel ( 'longle' );
  433. $product = new product ();
  434. $longle = new longle ();
  435. $data ['product'] = $product->getProudct ();
  436. foreach ( $data ['product'] as $key => $value ) {
  437. $data ['product'] [$key] ['count'] = $longle->count ( array (
  438. 'where' => 'product="' . $value ['title'] . '"'
  439. ) );
  440. }
  441. $this->render ( "/admin/admin_product", $data );
  442. }
  443. function addproduct() {
  444. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  445. if (! empty ( $title )) {
  446. Doo::loadModel ( 'product' );
  447. $product = new product ();
  448. $product->title = $title;
  449. $product->insert ();
  450. }
  451. return "/adminproduct";
  452. }
  453. function adminDeleteProduct() {
  454. $pid = is_numeric ( $this->params ['pid'] ) ? $this->params ['pid'] : 0;
  455. if (! empty ( $pid )) {
  456. Doo::loadModel ( 'product' );
  457. $product = new product ();
  458. $product->pid = $pid;
  459. $product->delete ();
  460. }
  461. return "/adminproduct";
  462. }
  463. function adminEdiProduct() {
  464. $pid = is_numeric ( $this->params ['pid'] ) ? $this->params ['pid'] : 0;
  465. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  466. if (! empty ( $pid )) {
  467. $data ['msg'] = urldecode ( $msg );
  468. Doo::loadModel ( 'product' );
  469. $product = new product ();
  470. $data ['productInfo'] = $product->getProductById ( $pid );
  471. $data ['memu'] = "adminproduct";
  472. $data ['staff'] = $this->staff;
  473. $this->render ( "/admin/admin_EdiProduct", $data );
  474. } else
  475. return "/adminproduct";
  476. }
  477. function adminDoEdiProduct() {
  478. $pid = is_numeric ( $this->get_args ( 'pid' ) ) ? $this->get_args ( 'pid' ) : "";
  479. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  480. $typeid = $this->get_args ( 'typeid' ) ? $this->get_args ( 'typeid' ) : "";
  481. if (! empty ( $pid ) && ! empty ( $title ) && ! empty ( $typeid )) {
  482. $msg = "";
  483. Doo::loadModel ( 'product' );
  484. $product = new product ();
  485. $product->pid = $pid;
  486. $product->title = $title;
  487. $product->typeid = $typeid;
  488. $product->update ();
  489. return "/adminproduct";
  490. } else {
  491. return "/adminproduct";
  492. }
  493. }
  494. function adminverify() {
  495. Doo::loadModel ( 'staff' );
  496. Doo::loadModel ( "verify" );
  497. $verify = new verify ();
  498. $staff = new staff ();
  499. Doo::loadModel ( "role" );
  500. $role = new role ();
  501. $data ['staffList'] = $staff->find ( array (
  502. 'select' => 'username,sid,avatar',
  503. 'asArray' => true
  504. ) );
  505. $list = $verify->find ( array (
  506. 'asArray' => true
  507. ) );
  508. $roleList = $role->find ( array (
  509. 'asArray' => true
  510. ) );
  511. foreach ( $roleList as $key => $value ) {
  512. $staffList = json_decode ( $value ['staff'] );
  513. foreach ( $staffList as $k => $v ) {
  514. $staffList [$k] = substr ( strstr ( $v, '_' ), 1 );
  515. }
  516. $roleList [$key] ['staff'] = implode ( ',', $staffList );
  517. }
  518. foreach ( $list as $key => $value ) {
  519. $name = json_decode ( $value ['staff'] );
  520. $list [$key] ['staff'] = "";
  521. foreach ( $name as $k => $v ) {
  522. if ($v [1] == 'ROLE') {
  523. $roleInfo = $role->getOne ( array (
  524. 'where' => 'rid = "' . $v [0] . '"',
  525. 'asArray' => true
  526. ) );
  527. $v [1] = $roleInfo ['name'];
  528. }
  529. $list [$key] ['staff'] .= " " . $v [1];
  530. }
  531. }
  532. $data ['roleList'] = $roleList;
  533. $data ['verify'] = $list;
  534. $data ['memu'] = "verify";
  535. $data ['staff'] = $this->staff;
  536. $this->render ( "/admin/admin_reportGroup", $data );
  537. }
  538. function addVerify() {
  539. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  540. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  541. $uidlist = $this->get_args ( 'uidlist' ) ? $this->get_args ( 'uidlist' ) : "";
  542. $uidlist = explode ( ",", $uidlist );
  543. Doo::loadModel ( "role" );
  544. $role = new role ();
  545. $list = array ();
  546. foreach ( $uidlist as $key => $value ) {
  547. $info = explode ( ":", $value );
  548. if ($info [1] == 'ROLE') {
  549. $roleInfo = $role->getOne ( array (
  550. 'where' => 'rid = "' . $info [0] . '"',
  551. 'asArray' => true
  552. ) );
  553. array_push ( $info, $roleInfo ['staff'] );
  554. }
  555. array_push ( $list, $info );
  556. }
  557. if (! empty ( $description ) && ! empty ( $list )) {
  558. Doo::loadModel ( "verify" );
  559. $verify = new verify ();
  560. $verify->description = $description;
  561. $verify->staff = json_encode ( $list );
  562. $verify->insert ();
  563. }
  564. return "/adminverify";
  565. }
  566. function adminRole() {
  567. Doo::loadModel ( 'staff' );
  568. $staff = new staff ();
  569. Doo::loadModel ( "verify" );
  570. $verify = new verify ();
  571. Doo::loadModel ( "role" );
  572. $role = new role ();
  573. $data ['staffList'] = $staff->find ( array (
  574. 'select' => 'username,sid,avatar',
  575. 'asArray' => true
  576. ) );
  577. $list = $verify->find ( array (
  578. 'asArray' => true
  579. ) );
  580. $roleList = $role->find ( array (
  581. 'asArray' => true
  582. ) );
  583. foreach ( $list as $key => $value ) {
  584. $name = json_decode ( $value ['staff'] );
  585. $list [$key] ['staff'] = "";
  586. foreach ( $name as $k => $v ) {
  587. $list [$key] ['staff'] .= " " . $v [1];
  588. }
  589. }
  590. foreach ( $roleList as $key => $value ) {
  591. $staff = json_decode ( $value ['staff'] );
  592. foreach ( $staff as $k => $v ) {
  593. // print_r($info);
  594. // $staff[$k]=substr(strstr($v, '_'), 1);
  595. $info = explode ( '_', $v );
  596. $staff [$k] = $info;
  597. }
  598. $roleList [$key] ['list'] = $staff;
  599. }
  600. $data ['roleList'] = $roleList;
  601. $data ['verify'] = $list;
  602. $data ['memu'] = "verify";
  603. $data ['staff'] = $this->staff;
  604. $this->render ( "/admin/adminReportGroupRole", $data );
  605. }
  606. function addRole() {
  607. $name = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  608. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  609. $list = array ();
  610. foreach ( $staff as $key => $value ) {
  611. $na = explode ( ":", $value );
  612. array_push ( $list, $na [0] . '_' . $na [1] );
  613. }
  614. if (! empty ( $name ) && ! empty ( $list )) {
  615. Doo::loadModel ( "role" );
  616. $role = new role ();
  617. $role->name = $name;
  618. $role->staff = json_encode ( $list );
  619. $role->insert ();
  620. }
  621. return "/adminRole";
  622. }
  623. function delRole() {
  624. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  625. if (! empty ( $rid )) {
  626. Doo::loadModel ( "role" );
  627. $role = new role ();
  628. $role->delete ( array (
  629. 'where' => 'rid="' . $rid . '"'
  630. ) );
  631. }
  632. return "/adminRole";
  633. }
  634. function updateRole() {
  635. $oldStaff = $this->get_args ( 'oldStaff' ) ? $this->get_args ( 'oldStaff' ) : "";
  636. $newStaff = $this->get_args ( 'newStaff' ) ? $this->get_args ( 'newStaff' ) : "";
  637. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  638. if (! empty ( $oldStaff ) && ! empty ( $newStaff ) && ! empty ( $rid )) {
  639. Doo::loadModel ( "role" );
  640. $role = new role ();
  641. $roleInfo = $role->getOne ( array (
  642. 'where' => 'rid = "' . $rid . '"',
  643. 'asArray' => true
  644. ) );
  645. $staffList = json_decode ( $roleInfo ['staff'], true );
  646. foreach ( $staffList as $key => $value ) {
  647. if ($value == $oldStaff) {
  648. $staffList [$key] = $newStaff;
  649. break;
  650. }
  651. }
  652. $role->staff = json_encode ( $staffList );
  653. $role->update ( array (
  654. 'where' => 'rid = "' . $rid . '"'
  655. ) );
  656. }
  657. return "/adminRole";
  658. }
  659. function adminExecute() {
  660. Doo::loadModel ( 'staff' );
  661. $staff = new staff ();
  662. Doo::loadModel ( "execute" );
  663. $execute = new execute ();
  664. $data ['staffList'] = $staff->find ( array (
  665. 'select' => 'username,sid,avatar',
  666. 'asArray' => true
  667. ) );
  668. $list = $execute->find ( array (
  669. 'asArray' => true
  670. ) );
  671. $execute = array (
  672. '借款执行人' => '',
  673. '借款费用执行人' => '',
  674. '报销单执行人' => '',
  675. '对公汇款执行人' => ''
  676. );
  677. foreach ( $list as $key => $value ) {
  678. $name = json_decode ( $value ['staff'] );
  679. $staffString = "";
  680. if (! empty ( $name )) {
  681. foreach ( $name as $k => $v ) {
  682. $staffString .= " " . $v [1] . '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/delExecute/' . $v [0] . '/' . $value ['eid'] . '\'" title="删除" class="icon-">k</a>';
  683. }
  684. }
  685. foreach ( $execute as $k => $v ) {
  686. if ($k == $value ['mold']) {
  687. $execute [$k] = $name = $staffString;
  688. }
  689. }
  690. }
  691. // print_r($execute);die;
  692. $data ['execute'] = $execute;
  693. $data ['memu'] = "verify";
  694. $data ['staff'] = $this->staff;
  695. $this->render ( "/admin/adminCarriedout", $data );
  696. }
  697. function addExecute() {
  698. $mold = $this->get_args ( 'mold' ) ? $this->get_args ( 'mold' ) : "";
  699. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  700. if (! empty ( $mold ) && ! empty ( $staff )) {
  701. Doo::loadModel ( "execute" );
  702. $execute = new execute ();
  703. $executeInfo = $execute->getOne ( array (
  704. 'where' => 'mold ="' . $mold . '" ',
  705. 'asArray' => true
  706. ) );
  707. if (empty ( $executeInfo )) {
  708. $list = array ();
  709. foreach ( $staff as $key => $value ) {
  710. $info = explode ( ":", $value );
  711. array_push ( $list, $info );
  712. }
  713. $execute->mold = $mold;
  714. $execute->staff = json_encode ( $list );
  715. $execute->insert ();
  716. } else {
  717. $list = json_decode ( $executeInfo ['staff'], true );
  718. foreach ( $staff as $k => $v ) {
  719. $info = explode ( ":", $v );
  720. foreach ( $list as $key => $value ) {
  721. if ($value [1] == $info [1]) {
  722. unset ( $staff [$k] );
  723. break;
  724. }
  725. }
  726. }
  727. foreach ( $staff as $k => $v ) {
  728. $info = explode ( ":", $v );
  729. array_push ( $list, $info );
  730. }
  731. $execute->staff = json_encode ( $list );
  732. $execute->update ( array (
  733. 'where' => 'eid = ' . $executeInfo ['eid']
  734. ) );
  735. }
  736. }
  737. return "/adminExecute";
  738. }
  739. function delExecute() {
  740. $uid = isset ( $this->params ['uid'] ) && is_numeric ( $this->params ['uid'] ) ? $this->params ['uid'] : 0;
  741. $eid = isset ( $this->params ['eid'] ) && is_numeric ( $this->params ['eid'] ) ? $this->params ['eid'] : 0;
  742. if (! empty ( $uid ) && ! empty ( $eid )) {
  743. Doo::loadModel ( "execute" );
  744. $execute = new execute ();
  745. $executeInfo = $execute->getOne ( array (
  746. 'where' => 'eid ="' . $eid . '" ',
  747. 'asArray' => true
  748. ) );
  749. if (empty ( $executeInfo ))
  750. return "/adminExecute";
  751. $ini = array ();
  752. $list = json_decode ( $executeInfo ['staff'], true );
  753. foreach ( $list as $k => $v ) {
  754. if ($v [0] == $uid) {
  755. $ini = $list [$k];
  756. unset ( $list [$k] );
  757. break;
  758. }
  759. }
  760. file_put_contents ( "protected/config/execute/execute.ini", "," . $ini [0], FILE_APPEND );
  761. $execute->staff = json_encode ( $list );
  762. $execute->update ( array (
  763. 'where' => 'eid = ' . $executeInfo ['eid']
  764. ) );
  765. }
  766. return "/adminExecute";
  767. }
  768. function adminInvoice() {
  769. Doo::loadModel ( 'staff' );
  770. $staff = new staff ();
  771. Doo::loadModel ( "invoiceManage" );
  772. $invoiceManage = new invoiceManage ();
  773. $data ['staffList'] = $staff->find ( array (
  774. 'select' => 'username,sid,avatar',
  775. 'asArray' => true
  776. ) );
  777. $list = $invoiceManage->find ( array (
  778. 'asArray' => true
  779. ) );
  780. $execute = array (
  781. '收款管理' => '',
  782. '发票审批' => '',
  783. '发票打印' => '',
  784. '发票邮寄' => '',
  785. '发票退票' => '',
  786. '公司汇总查阅' => '',
  787. '纸票管理' => ''
  788. );
  789. foreach ( $list as $key => $value ) {
  790. $name = json_decode ( $value ['staff'] );
  791. $staffString = "";
  792. if (! empty ( $name )) {
  793. foreach ( $name as $k => $v ) {
  794. $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>';
  795. }
  796. }
  797. foreach ( $execute as $k => $v ) {
  798. if ($k == $value ['mold']) {
  799. $execute [$k] = $name = $staffString;
  800. }
  801. }
  802. }
  803. $data ['invoice'] = $execute;
  804. $data ['memu'] = "invoice";
  805. $data ['staff'] = $this->staff;
  806. $this->render ( "/admin/adminInvoice", $data );
  807. }
  808. function addInvoiceManage() {
  809. $mold = $this->get_args ( 'mold' ) ? $this->get_args ( 'mold' ) : "";
  810. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  811. if (! empty ( $mold ) && ! empty ( $staff )) {
  812. Doo::loadModel ( "invoiceManage" );
  813. $execute = new invoiceManage ();
  814. $executeInfo = $execute->getOne ( array (
  815. 'where' => 'mold ="' . $mold . '" ',
  816. 'asArray' => true
  817. ) );
  818. if (empty ( $executeInfo )) {
  819. $list = array ();
  820. foreach ( $staff as $key => $value ) {
  821. $info = explode ( ":", $value );
  822. array_push ( $list, $info );
  823. }
  824. $execute->mold = $mold;
  825. $execute->staff = json_encode ( $list );
  826. $execute->insert ();
  827. } else {
  828. $list = json_decode ( $executeInfo ['staff'], true );
  829. foreach ( $staff as $k => $v ) {
  830. $info = explode ( ":", $v );
  831. foreach ( $list as $key => $value ) {
  832. if ($value [1] == $info [1]) {
  833. unset ( $staff [$k] );
  834. break;
  835. }
  836. }
  837. }
  838. foreach ( $staff as $k => $v ) {
  839. $info = explode ( ":", $v );
  840. array_push ( $list, $info );
  841. }
  842. $execute->staff = json_encode ( $list );
  843. $execute->update ( array (
  844. 'where' => 'iid = ' . $executeInfo ['iid']
  845. ) );
  846. }
  847. }
  848. return "/adminInvoice";
  849. }
  850. /**
  851. * 发票相关权限配置,把相关组的审批人删除。不会影响已经生成发票数据,修改后只会影响修改后生成的发票数据
  852. * @return string 返回配置页
  853. */
  854. function delInvoiceManage() {
  855. $uid = isset ( $this->params ['uid'] ) && is_numeric ( $this->params ['uid'] ) ? $this->params ['uid'] : 0;
  856. $iid = isset ( $this->params ['iid'] ) && is_numeric ( $this->params ['iid'] ) ? $this->params ['iid'] : 0;
  857. if (! empty ( $uid ) && ! empty ( $iid )) {
  858. Doo::loadModel ( "invoiceManage" );
  859. $execute = new invoiceManage ();
  860. $executeInfo = $execute->getOne ( array (
  861. 'where' => 'iid ="' . $iid . '" ',
  862. 'asArray' => true
  863. ) );
  864. if (empty ( $executeInfo ))
  865. return "/adminInvoice";
  866. $ini = array ();
  867. $list = json_decode ( $executeInfo ['staff'], true );
  868. foreach ( $list as $k => $v ) {
  869. if ($v [0] == $uid) {
  870. $ini = $list [$k];
  871. unset ( $list [$k] );
  872. break;
  873. }
  874. }
  875. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  876. if (! empty ( $fileInvoice )) {
  877. $fileInvoice = json_decode ( $fileInvoice, true );
  878. if (isset ( $fileInvoice [$executeInfo ['mold']] ))
  879. $fileInvoice [$executeInfo ['mold']] .= "," . $ini [0];
  880. else
  881. $fileInvoice [$executeInfo ['mold']] = '';
  882. $moldArray = explode ( ',', $fileInvoice [$executeInfo ['mold']] );
  883. $moldArray = array_unique ( $moldArray );
  884. $fileInvoice [$executeInfo ['mold']] = implode ( ',', $moldArray );
  885. $fileInvoice = json_encode ( $fileInvoice );
  886. file_put_contents ( "protected/config/invoice/invoice.ini", $fileInvoice );
  887. } else {
  888. $fileInvoice = array (
  889. $executeInfo ['mold'] => $ini [0]
  890. );
  891. $fileInvoice = json_encode ( $fileInvoice );
  892. file_put_contents ( "protected/config/invoice/invoice.ini", $fileInvoice );
  893. }
  894. file_put_contents ( "protected/config/execute/invoice.ini", "," . $ini [0], FILE_APPEND );
  895. $execute->staff = json_encode ( $list );
  896. $execute->update ( array (
  897. 'where' => 'iid = ' . $executeInfo ['iid']
  898. ) );
  899. }
  900. return "/adminInvoice";
  901. }
  902. /**
  903. * 报销单汇总权限配置
  904. */
  905. function adminReceiptAuthority(){
  906. Doo::loadClass ( 'XDeode' );
  907. $XDeode = new XDeode ( 5 );
  908. Doo::loadModel ( 'staff' );
  909. $staff = new staff ();
  910. Doo::loadModel ( "receiptAuthorityManage" );
  911. $receiptAuthorityManage = new receiptAuthorityManage ();
  912. Doo::loadModel ( 'L_category' );
  913. $category = new L_category ();
  914. $categoryList = $category->getCategory ();
  915. $managelist = $receiptAuthorityManage->find ( array (
  916. 'asArray' => true
  917. ) );
  918. $staffList = $staff->getStaff ();
  919. $invoiceStaff = array ();
  920. foreach ( $categoryList as $key => $value ) {
  921. $invoiceStaff [$value ['cidKey']] = array ();
  922. $categoryList [$key] ['html'] = '';
  923. foreach ( $staffList as $k => $v ) {
  924. $ul = array ();
  925. if ($value ['cid'] == $v ['cid']) {
  926. array_push ( $ul, $v ['sidKey'] );
  927. array_push ( $ul, $v ['username'] );
  928. array_push ( $invoiceStaff [$value ['cidKey']], $ul );
  929. }
  930. }
  931. foreach ( $managelist as $e => $a ) {
  932. if ($value ['cid'] == $a ['cid']) {
  933. $name = json_decode ( $a ['staff'] );
  934. $staffString = "";
  935. foreach ( $name as $y => $l ) {
  936. $sidKey = $XDeode->encode ( $l [0] );
  937. $icidKey = $XDeode->encode ( $a ['icid'] );
  938. $staffString .= $l [1] . '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/delReceiptAuthorityManage/' . $sidKey . '/' . $icidKey . '\'" role="button" title="删除" class="icon-">k</a>&nbsp;';
  939. }
  940. $categoryList [$key] ['html'] = $staffString;
  941. break;
  942. }
  943. }
  944. }
  945. $data ['categoryList'] = $categoryList;
  946. $data ['invoiceStaff'] = json_encode ( $invoiceStaff );
  947. $data ['memu'] = "verify";
  948. $data ['staff'] = $this->staff;
  949. $this->render ( "/admin/adminReceiptAuthority", $data );
  950. }
  951. /**
  952. * 添加报销单汇总查看权限
  953. */
  954. function addReceiptAuthorityManage() {
  955. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : "";
  956. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : "";
  957. if (! empty ( $cidKey ) && ! empty ( $sidKey )) {
  958. Doo::loadModel ( "receiptAuthorityManage" );
  959. $receiptAuthorityManage = new receiptAuthorityManage ();
  960. Doo::loadClass ( 'XDeode' );
  961. $XDeode = new XDeode ( 5 );
  962. Doo::loadModel ( 'staff' );
  963. $staff = new staff ();
  964. $cid = $XDeode->decode ( $cidKey );
  965. $sid = $XDeode->decode ( $sidKey );
  966. if (! is_numeric ( $cid ) || ! is_numeric ( $sid ))
  967. die ( 'illegal request' );
  968. $icm = $receiptAuthorityManage->getOne ( array (
  969. 'where' => 'cid =' . $cid,
  970. 'asArray' => true
  971. ) );
  972. $staffDetail = $staff->getStaffBySid ( $sid );
  973. if (empty ( $icm )) {
  974. $receiptAuthorityManage = new receiptAuthorityManage ();
  975. $list = array ();
  976. $info = array (
  977. $staffDetail ['sid'],
  978. $staffDetail ['username']
  979. );
  980. array_push ( $list, $info );
  981. $receiptAuthorityManage->cid = $cid;
  982. $receiptAuthorityManage->staff = json_encode ( $list );
  983. $receiptAuthorityManage->insert ();
  984. } else {
  985. $invoiceCompanyManage = new receiptAuthorityManage ();
  986. $list = json_decode ( $icm ['staff'], true );
  987. $flag = true;
  988. foreach ( $list as $key => $value ) {
  989. if ($value [0] == $sid) {
  990. $flag = false;
  991. break;
  992. }
  993. }
  994. if ($flag) {
  995. $info = array (
  996. $staffDetail ['sid'],
  997. $staffDetail ['username']
  998. );
  999. array_push ( $list, $info );
  1000. }
  1001. $invoiceCompanyManage->staff = json_encode ( $list );
  1002. $invoiceCompanyManage->update ( array (
  1003. 'where' => 'icid = ' . $icm ['icid']
  1004. ) );
  1005. }
  1006. return '/adminReceiptAuthority';
  1007. }
  1008. die ( 'illegal request' );
  1009. }
  1010. /**
  1011. * 去除查看办事处汇总人员
  1012. */
  1013. function delReceiptAuthorityManage() {
  1014. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  1015. $icidKey = isset ( $this->params ['icidKey'] ) ? $this->params ['icidKey'] : '';
  1016. Doo::loadClass ( 'XDeode' );
  1017. $XDeode = new XDeode ( 5 );
  1018. $icid = $XDeode->decode ( $icidKey );
  1019. $sid = $XDeode->decode ( $sidKey );
  1020. if (! is_numeric ( $icid ) || ! is_numeric ( $sid ))
  1021. die ( 'illegal request' );
  1022. Doo::loadModel ( "receiptAuthorityManage" );
  1023. $receiptAuthorityManage = new receiptAuthorityManage ();
  1024. $icmDetail = $receiptAuthorityManage->getInvoiceCMByIcid ( $icid );
  1025. if (empty ( $icmDetail ))
  1026. die ( 'illegal request' );
  1027. $list = json_decode ( $icmDetail ['staff'], true );
  1028. foreach ( $list as $k => $v ) {
  1029. if ($v [0] == $sid) {
  1030. unset ( $list [$k] );
  1031. break;
  1032. }
  1033. }
  1034. $invoiceCompanyManage = new receiptAuthorityManage ();
  1035. $invoiceCompanyManage->staff = json_encode ( $list );
  1036. $invoiceCompanyManage->update ( array (
  1037. 'where' => 'icid = ' . $icmDetail ['icid']
  1038. ) );
  1039. return '/adminReceiptAuthority';
  1040. }
  1041. /**
  1042. * 开票应收款权限设置
  1043. */
  1044. function adminInvoiceCompany() {
  1045. Doo::loadClass ( 'XDeode' );
  1046. $XDeode = new XDeode ( 5 );
  1047. Doo::loadModel ( 'staff' );
  1048. $staff = new staff ();
  1049. Doo::loadModel ( "invoiceCompanyManage" );
  1050. $invoiceCompanyManage = new invoiceCompanyManage ();
  1051. Doo::loadModel ( 'L_category' );
  1052. $category = new L_category ();
  1053. $categoryList = $category->getCategory ();
  1054. $managelist = $invoiceCompanyManage->find ( array (
  1055. 'asArray' => true
  1056. ) );
  1057. $staffList = $staff->getStaff ();
  1058. $invoiceStaff = array ();
  1059. foreach ( $categoryList as $key => $value ) {
  1060. $invoiceStaff [$value ['cidKey']] = array ();
  1061. $categoryList [$key] ['html'] = '';
  1062. foreach ( $staffList as $k => $v ) {
  1063. $ul = array ();
  1064. if ($value ['cid'] == $v ['cid']) {
  1065. array_push ( $ul, $v ['sidKey'] );
  1066. array_push ( $ul, $v ['username'] );
  1067. array_push ( $invoiceStaff [$value ['cidKey']], $ul );
  1068. }
  1069. }
  1070. foreach ( $managelist as $e => $a ) {
  1071. if ($value ['cid'] == $a ['cid']) {
  1072. $name = json_decode ( $a ['staff'] );
  1073. $staffString = "";
  1074. foreach ( $name as $y => $l ) {
  1075. $sidKey = $XDeode->encode ( $l [0] );
  1076. $icidKey = $XDeode->encode ( $a ['icid'] );
  1077. $staffString .= $l [1] . '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/delInvoiceCompanyManage/' . $sidKey . '/' . $icidKey . '\'" role="button" title="删除" class="icon-">k</a>&nbsp;';
  1078. }
  1079. $categoryList [$key] ['html'] = $staffString;
  1080. break;
  1081. }
  1082. }
  1083. }
  1084. $data ['categoryList'] = $categoryList;
  1085. $data ['invoiceStaff'] = json_encode ( $invoiceStaff );
  1086. $data ['memu'] = "invoice";
  1087. $data ['staff'] = $this->staff;
  1088. $this->render ( "/admin/adminInvoiceCompany", $data );
  1089. }
  1090. /**
  1091. * 添加办事处查看权限
  1092. */
  1093. function addInvoiceCompanyManage() {
  1094. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : "";
  1095. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : "";
  1096. if (! empty ( $cidKey ) && ! empty ( $sidKey )) {
  1097. Doo::loadModel ( "invoiceCompanyManage" );
  1098. $invoiceCompanyManage = new invoiceCompanyManage ();
  1099. Doo::loadClass ( 'XDeode' );
  1100. $XDeode = new XDeode ( 5 );
  1101. Doo::loadModel ( 'staff' );
  1102. $staff = new staff ();
  1103. $cid = $XDeode->decode ( $cidKey );
  1104. $sid = $XDeode->decode ( $sidKey );
  1105. if (! is_numeric ( $cid ) || ! is_numeric ( $sid ))
  1106. die ( 'illegal request' );
  1107. $icm = $invoiceCompanyManage->getOne ( array (
  1108. 'where' => 'cid =' . $cid,
  1109. 'asArray' => true
  1110. ) );
  1111. $staffDetail = $staff->getStaffBySid ( $sid );
  1112. if (empty ( $icm )) {
  1113. $invoiceCompanyManage = new invoiceCompanyManage ();
  1114. $list = array ();
  1115. $info = array (
  1116. $staffDetail ['sid'],
  1117. $staffDetail ['username']
  1118. );
  1119. array_push ( $list, $info );
  1120. $invoiceCompanyManage->cid = $cid;
  1121. $invoiceCompanyManage->staff = json_encode ( $list );
  1122. $invoiceCompanyManage->insert ();
  1123. } else {
  1124. $invoiceCompanyManage = new invoiceCompanyManage ();
  1125. $list = json_decode ( $icm ['staff'], true );
  1126. $flag = true;
  1127. foreach ( $list as $key => $value ) {
  1128. if ($value [0] == $sid) {
  1129. $flag = false;
  1130. break;
  1131. }
  1132. }
  1133. if ($flag) {
  1134. $info = array (
  1135. $staffDetail ['sid'],
  1136. $staffDetail ['username']
  1137. );
  1138. array_push ( $list, $info );
  1139. }
  1140. $invoiceCompanyManage->staff = json_encode ( $list );
  1141. $invoiceCompanyManage->update ( array (
  1142. 'where' => 'icid = ' . $icm ['icid']
  1143. ) );
  1144. }
  1145. return '/adminInvoiceCompany';
  1146. }
  1147. die ( 'illegal request' );
  1148. }
  1149. /**
  1150. * 去除查看办事处汇总人员
  1151. */
  1152. function delInvoiceCompanyManage() {
  1153. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  1154. $icidKey = isset ( $this->params ['icidKey'] ) ? $this->params ['icidKey'] : '';
  1155. Doo::loadClass ( 'XDeode' );
  1156. $XDeode = new XDeode ( 5 );
  1157. $icid = $XDeode->decode ( $icidKey );
  1158. $sid = $XDeode->decode ( $sidKey );
  1159. if (! is_numeric ( $icid ) || ! is_numeric ( $sid ))
  1160. die ( 'illegal request' );
  1161. Doo::loadModel ( "invoiceCompanyManage" );
  1162. $invoiceCompanyManage = new invoiceCompanyManage ();
  1163. $icmDetail = $invoiceCompanyManage->getInvoiceCMByIcid ( $icid );
  1164. if (empty ( $icmDetail ))
  1165. die ( 'illegal request' );
  1166. $list = json_decode ( $icmDetail ['staff'], true );
  1167. foreach ( $list as $k => $v ) {
  1168. if ($v [0] == $sid) {
  1169. unset ( $list [$k] );
  1170. break;
  1171. }
  1172. }
  1173. $invoiceCompanyManage = new invoiceCompanyManage ();
  1174. $invoiceCompanyManage->staff = json_encode ( $list );
  1175. $invoiceCompanyManage->update ( array (
  1176. 'where' => 'icid = ' . $icmDetail ['icid']
  1177. ) );
  1178. return '/adminInvoiceCompany';
  1179. }
  1180. /**
  1181. * 开票办事处权限设置
  1182. */
  1183. function adminInvoiceCategory() {
  1184. Doo::loadClass ( 'XDeode' );
  1185. $XDeode = new XDeode ( 5 );
  1186. Doo::loadModel ( 'staff' );
  1187. $staff = new staff ();
  1188. Doo::loadModel ( "invoiceCategoryManage" );
  1189. $invoiceCategoryManage = new invoiceCategoryManage ();
  1190. Doo::loadModel ( 'L_category' );
  1191. $category = new L_category ();
  1192. $categoryList = $category->getCategory ();
  1193. $managelist = $invoiceCategoryManage->find ( array (
  1194. 'asArray' => true
  1195. ) );
  1196. $staffList = $staff->getStaff ();
  1197. $invoiceStaff = array ();
  1198. foreach ( $categoryList as $key => $value ) {
  1199. $invoiceStaff [$value ['cidKey']] = array ();
  1200. $categoryList [$key] ['html'] = '';
  1201. foreach ( $staffList as $k => $v ) {
  1202. $ul = array ();
  1203. if ($value ['cid'] == $v ['cid']) {
  1204. array_push ( $ul, $v ['sidKey'] );
  1205. array_push ( $ul, $v ['username'] );
  1206. array_push ( $invoiceStaff [$value ['cidKey']], $ul );
  1207. }
  1208. }
  1209. foreach ( $managelist as $e => $a ) {
  1210. if ($value ['cid'] == $a ['cid']) {
  1211. $name = json_decode ( $a ['staff'] );
  1212. $staffString = "";
  1213. foreach ( $name as $y => $l ) {
  1214. $sidKey = $XDeode->encode ( $l [0] );
  1215. $icidKey = $XDeode->encode ( $a ['icid'] );
  1216. $staffString .= $l [1] . '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/delInvoiceCategoryManage/' . $sidKey . '/' . $icidKey . '\'" role="button" title="删除" class="icon-">k</a>&nbsp;';
  1217. }
  1218. $categoryList [$key] ['html'] = $staffString;
  1219. break;
  1220. }
  1221. }
  1222. }
  1223. // print_r($invoiceStaff);
  1224. $data ['categoryList'] = $categoryList;
  1225. $data ['invoiceStaff'] = json_encode ( $invoiceStaff );
  1226. $data ['memu'] = "invoice";
  1227. $data ['staff'] = $this->staff;
  1228. $this->render ( "/admin/adminInvoiceCategory", $data );
  1229. }
  1230. /**
  1231. * 添加办事处查看权限
  1232. */
  1233. function addInvoiceCategoryManage() {
  1234. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : "";
  1235. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : "";
  1236. if (! empty ( $cidKey ) && ! empty ( $sidKey )) {
  1237. Doo::loadModel ( "invoiceCategoryManage" );
  1238. $invoiceCategoryManage = new invoiceCategoryManage ();
  1239. Doo::loadClass ( 'XDeode' );
  1240. $XDeode = new XDeode ( 5 );
  1241. Doo::loadModel ( 'staff' );
  1242. $staff = new staff ();
  1243. $cid = $XDeode->decode ( $cidKey );
  1244. $sid = $XDeode->decode ( $sidKey );
  1245. if (! is_numeric ( $cid ) || ! is_numeric ( $sid ))
  1246. die ( 'illegal request' );
  1247. $icm = $invoiceCategoryManage->getOne ( array (
  1248. 'where' => 'cid =' . $cid,
  1249. 'asArray' => true
  1250. ) );
  1251. $staffDetail = $staff->getStaffBySid ( $sid );
  1252. if (empty ( $icm )) {
  1253. $invoiceCategoryManage = new invoiceCategoryManage ();
  1254. $list = array ();
  1255. $info = array (
  1256. $staffDetail ['sid'],
  1257. $staffDetail ['username']
  1258. );
  1259. array_push ( $list, $info );
  1260. $invoiceCategoryManage->cid = $cid;
  1261. $invoiceCategoryManage->staff = json_encode ( $list );
  1262. $invoiceCategoryManage->insert ();
  1263. } else {
  1264. $invoiceCategoryManage = new invoiceCategoryManage ();
  1265. $list = json_decode ( $icm ['staff'], true );
  1266. $flag = true;
  1267. foreach ( $list as $key => $value ) {
  1268. if ($value [0] == $sid) {
  1269. $flag = false;
  1270. break;
  1271. }
  1272. }
  1273. if ($flag) {
  1274. $info = array (
  1275. $staffDetail ['sid'],
  1276. $staffDetail ['username']
  1277. );
  1278. array_push ( $list, $info );
  1279. }
  1280. $invoiceCategoryManage->staff = json_encode ( $list );
  1281. $invoiceCategoryManage->update ( array (
  1282. 'where' => 'icid = ' . $icm ['icid']
  1283. ) );
  1284. }
  1285. return '/adminInvoiceCategory';
  1286. }
  1287. die ( 'illegal request' );
  1288. }
  1289. /**
  1290. * 去除查看办事处汇总人员
  1291. */
  1292. function delInvoiceCategoryManage() {
  1293. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  1294. $icidKey = isset ( $this->params ['icidKey'] ) ? $this->params ['icidKey'] : '';
  1295. Doo::loadClass ( 'XDeode' );
  1296. $XDeode = new XDeode ( 5 );
  1297. $icid = $XDeode->decode ( $icidKey );
  1298. $sid = $XDeode->decode ( $sidKey );
  1299. if (! is_numeric ( $icid ) || ! is_numeric ( $sid ))
  1300. die ( 'illegal request' );
  1301. Doo::loadModel ( "invoiceCategoryManage" );
  1302. $invoiceCategoryManage = new invoiceCategoryManage ();
  1303. $icmDetail = $invoiceCategoryManage->getInvoiceCMByIcid ( $icid );
  1304. if (empty ( $icmDetail ))
  1305. die ( 'illegal request' );
  1306. $list = json_decode ( $icmDetail ['staff'], true );
  1307. foreach ( $list as $k => $v ) {
  1308. if ($v [0] == $sid) {
  1309. unset ( $list [$k] );
  1310. break;
  1311. }
  1312. }
  1313. $invoiceCategoryManage = new invoiceCategoryManage ();
  1314. $invoiceCategoryManage->staff = json_encode ( $list );
  1315. $invoiceCategoryManage->update ( array (
  1316. 'where' => 'icid = ' . $icmDetail ['icid']
  1317. ) );
  1318. return '/adminInvoiceCategory';
  1319. }
  1320. function ajaxRoleStaff() {
  1321. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  1322. Doo::loadModel ( 'staff' );
  1323. $staff = new staff ();
  1324. $staffList = $staff->find ( array (
  1325. 'select' => 'username,sid,avatar',
  1326. 'where' => 'username != "' . $name . '" and username !="admin"',
  1327. 'asArray' => true
  1328. ) );
  1329. $html = '';
  1330. foreach ( $staffList as $key => $value ) {
  1331. $html .= '<option value=' . $value ['sid'] . '_' . $value ['username'] . '>' . $value ['username'] . '</option>';
  1332. }
  1333. echo json_encode ( array (
  1334. "success" => true,
  1335. 'html' => $html
  1336. ) );
  1337. die ();
  1338. }
  1339. function loadCVS() {
  1340. Doo::loadModel ( 'longle' );
  1341. $longle = new longle ();
  1342. $list = $longle->find ( array (
  1343. 'select' => 'key_num',
  1344. 'asArray' => TRUE
  1345. ) );
  1346. $file = fopen ( DOO::conf ()->SITE_PATH . "upload/key2.csv", 'r' );
  1347. while ( $data = fgetcsv ( $file ) ) {
  1348. $goods_list [$data [0]] = $data [1];
  1349. }
  1350. fclose ( $file );
  1351. $sqlArray = array ();
  1352. $sql = 'UPDATE CLD_longle SET SerialNumber = CASE key_num ';
  1353. foreach ( $list as $key => $value ) {
  1354. if (array_key_exists ( $value ['key_num'], $goods_list )) {
  1355. // echo $value['key_num'].'-'.$goods_list[$value['key_num']].'<br/>';
  1356. // $longle->SerialNumber=$goods_list[$value['key_num']];
  1357. // $longle->update(array('where'=>'key_num="'.$value['key_num'].'"'));
  1358. $sql .= ' WHEN "' . $value ['key_num'] . '" THEN "' . $goods_list [$value ['key_num']] . '" ';
  1359. array_push ( $sqlArray, '"' . $value ['key_num'] . '"' );
  1360. unset ( $goods_list [$value ['key_num']] );
  1361. }
  1362. }
  1363. $sql .= 'END WHERE key_num IN (' . implode ( ',', $sqlArray ) . ')';
  1364. echo $sql . '<br/>--------------------------------<br/>';
  1365. foreach ( $goods_list as $key => $value ) {
  1366. echo $key . ',' . $value . '<br/>';
  1367. }
  1368. }
  1369. private function getRandChar($length) {
  1370. $str = null;
  1371. $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
  1372. $max = strlen ( $strPol ) - 1;
  1373. for($i = 0; $i < $length; $i ++) {
  1374. $str .= $strPol [rand ( 0, $max )]; // rand($min,$max)生成介于min和max两个数之间的一个随机整数
  1375. }
  1376. return $str;
  1377. }
  1378. private function getReceiptCount() {
  1379. $status = 2;
  1380. $year = date ( 'Y' );
  1381. Doo::loadModel ( 'receipt' );
  1382. $receipt = new receipt ();
  1383. Doo::loadModel ( 'verify' );
  1384. $verify = new verify ();
  1385. // user verify ID
  1386. $vidList = array ();
  1387. $verifyDetail = $verify->find ( array (
  1388. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '\"%"',
  1389. 'asArray' => true
  1390. ) );
  1391. foreach ( $verifyDetail as $key => $value ) {
  1392. array_push ( $vidList, $value ['vid'] );
  1393. }
  1394. $vid = implode ( ",", $vidList );
  1395. if (empty ( $verifyDetail ))
  1396. $vid = 0;
  1397. $dateCondition = " and Year(date) =" . $year;
  1398. $approvalCondition = ' and verifyStaff not like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  1399. $receiptList = $receipt->find ( array (
  1400. 'where' => 'verify in(' . $vid . ') and status=' . $status . $dateCondition . $approvalCondition,
  1401. 'desc' => 'rid',
  1402. 'asArray' => true
  1403. ) );
  1404. return count ( $receiptList );
  1405. }
  1406. /**
  1407. * 格式化excel文件为数组
  1408. * @param unknown_type $file_url
  1409. * @param unknown_type $mcid
  1410. */
  1411. function _format_excel_to_array($file_url = "") {
  1412. if (! file_exists ( $file_url ))
  1413. return array ();
  1414. Doo::loadClass ( 'PHPExcel' );
  1415. $PHPExcel = new PHPExcel ();
  1416. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  1417. if (! $PHPReader->canRead ( $file_url )) {
  1418. $PHPReader = new PHPExcel_Reader_Excel5 ();
  1419. if (! $PHPReader->canRead ( $file_url )) {
  1420. echo 'no Excel';
  1421. return;
  1422. }
  1423. }
  1424. $PHPExcel = $PHPReader->load ( $file_url );
  1425. /**
  1426. * 读取excel文件中的第一个工作表
  1427. */
  1428. $currentSheet = $PHPExcel->getSheet ( 0 );
  1429. /**
  1430. * 取得最大的列号
  1431. */
  1432. $allColumn = $currentSheet->getHighestColumn ();
  1433. /**
  1434. * 取得一共有多少行
  1435. */
  1436. $allRow = $currentSheet->getHighestRow ();
  1437. $excel_array = array ();
  1438. for($currentRow = 2; $currentRow <= $allRow; $currentRow ++) {
  1439. $excel_column = array ();
  1440. // 后期改进
  1441. if ($allColumn == 'AM')
  1442. $allColumn = 'Z';
  1443. /**
  1444. * 从第A列开始输出
  1445. */
  1446. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  1447. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  1448. /**
  1449. * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312',
  1450. */
  1451. $val = "'" . addslashes ( $val ) . "'";
  1452. if ($currentColumn == 'A')
  1453. $excel_column ['key_num'] = $val;
  1454. elseif ($currentColumn == 'C')
  1455. $excel_column ['product'] = $val;
  1456. elseif ($currentColumn == 'D') {
  1457. $val = str_replace ( "'", "", $val );
  1458. $excel_column ['make_day'] = $this->excelTime ( $val );
  1459. } elseif ($currentColumn == 'E') {
  1460. $val = str_replace ( "'", "", $val );
  1461. $excel_column ['alloted_time'] = $this->excelTime ( $val );
  1462. } elseif ($currentColumn == 'F') {
  1463. $val = str_replace ( "'", "", $val );
  1464. $excel_column ['version'] = $val;
  1465. } elseif ($currentColumn == 'B') {
  1466. $val = str_replace ( "'", "", $val );
  1467. $excel_column ['SerialNumber'] = $val;
  1468. }
  1469. }
  1470. array_push ( $excel_array, $excel_column );
  1471. }
  1472. return $excel_array;
  1473. }
  1474. function excelTime($date, $time = false) {
  1475. if (function_exists ( 'GregorianToJD' )) {
  1476. if (is_numeric ( $date )) {
  1477. $jd = GregorianToJD ( 1, 1, 1970 );
  1478. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  1479. $date = explode ( '/', $gregorian );
  1480. $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" : '');
  1481. return $date_str;
  1482. }
  1483. } else {
  1484. $date = $date > 25568 ? $date + 1 : 25569;
  1485. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  1486. $ofs = (70 * 365 + 17 + 2) * 86400;
  1487. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  1488. }
  1489. return $date;
  1490. }
  1491. function _GetFileEXT($filename) {
  1492. $pics = explode ( '.', $filename );
  1493. $num = count ( $pics );
  1494. return $pics [$num - 1];
  1495. }
  1496. /**
  1497. * 获取get或者POST值
  1498. * @param string $name 属性名称
  1499. * @return fixed 值
  1500. */
  1501. function get_args($name) {
  1502. if (isset ( $_GET [$name] )) {
  1503. if (is_array ( $_GET [$name] ))
  1504. return $_GET [$name];
  1505. else {
  1506. return addslashes ( $_GET [$name] );
  1507. }
  1508. } elseif (isset ( $_POST [$name] )) {
  1509. if (is_array ( $_POST [$name] ))
  1510. return $_POST [$name];
  1511. else {
  1512. return addslashes ( $_POST [$name] );
  1513. }
  1514. } else {
  1515. return false;
  1516. }
  1517. }
  1518. function get_previous($on_page = 1) {
  1519. return $on_page != 0 ? $on_page - 1 : $on_page;
  1520. }
  1521. /**
  1522. * 获得分页数据
  1523. * @param unknown_type $table
  1524. * @param unknown_type $condition
  1525. * @param unknown_type $on_page
  1526. * @param unknown_type $page_size
  1527. */
  1528. function get_Tpage($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $tagSQL) {
  1529. $page_c = "";
  1530. $page ['previous'] = $this->get_previous ( $on_page );
  1531. $page ['on_page'] = $on_page;
  1532. $total_count = $this->get_table_Tcount ( $table, $condition, $tagSQL );
  1533. $total = intval ( $total_count / $page_size );
  1534. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  1535. $page ['total_data'] = $total_count;
  1536. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  1537. $i = 1;
  1538. $page_max = 1;
  1539. if ($on_page > 10) {
  1540. $page_max = intval ( $on_page / 10 ) + 1;
  1541. $i = intval ( $on_page / 10 ) * 10 - 1;
  1542. }
  1543. $page ['page'] = $page_c;
  1544. $page ['lower'] = (-- $on_page) * $page_size;
  1545. return $page;
  1546. }
  1547. /**
  1548. * 获得分页数据
  1549. * @param unknown_type $table
  1550. * @param unknown_type $condition
  1551. * @param unknown_type $on_page
  1552. * @param unknown_type $page_size
  1553. */
  1554. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page", $staffid = "", $search, $tooltip, $cateid, $tagSQL) {
  1555. $page_c = "";
  1556. $page ['previous'] = $this->get_previous ( $on_page );
  1557. $page ['on_page'] = $on_page;
  1558. $total_count = $this->get_table_count ( $table, $condition, $staffid, $search, $tooltip, $cateid, $tagSQL );
  1559. $total = intval ( $total_count / $page_size );
  1560. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  1561. $page ['total_data'] = $total_count;
  1562. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  1563. $i = 1;
  1564. $page_max = 1;
  1565. if ($on_page > 10) {
  1566. $page_max = intval ( $on_page / 10 ) + 1;
  1567. $i = intval ( $on_page / 10 ) * 10 - 1;
  1568. }
  1569. for(; $i <= $page ['total_page']; $i ++) {
  1570. if ($i == $on_page) {
  1571. if ($other == "page")
  1572. $page_c .= '<a href="javascript:void(0);" class="current">' . $i . '</a>';
  1573. else
  1574. $page_c .= '&nbsp;<span class="current">' . $i . '</span>&nbsp;';
  1575. } else if ($other == "page")
  1576. $page_c .= '<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>';
  1577. else
  1578. $page_c .= '&nbsp;<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>&nbsp;';
  1579. if ($i == (10 * $page_max))
  1580. break;
  1581. }
  1582. $page ['page'] = $page_c;
  1583. $page ['lower'] = (-- $on_page) * $page_size;
  1584. return $page;
  1585. }
  1586. /**
  1587. * 获取总页数
  1588. * @param unknown_type $table
  1589. * @param unknown_type $condition
  1590. */
  1591. public function get_table_Tcount($table = "", $condition = "", $tagSQL) {
  1592. if ($tagSQL)
  1593. $sql = "select count(*) as count from CLD_tagCompanyNexus as a left join CLD_company as b on (a.company=b.cid ) where " . $condition;
  1594. else
  1595. $sql = "select count(*) as count from CLD_company where " . $condition;
  1596. $query = Doo::db ()->query ( $sql );
  1597. $result = $query->fetch ();
  1598. return $result ['count'];
  1599. }
  1600. /**
  1601. * 获取总页数
  1602. * @param unknown_type $table
  1603. * @param unknown_type $condition
  1604. */
  1605. public function get_table_count($table = "", $condition = "", $staffid = "", $search, $tooltip, $cateid, $tagSQL) {
  1606. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  1607. // echo $staffid;die;
  1608. //
  1609. if (! empty ( $staffid )) {
  1610. // $staffid="and a.sid= '".$staffid."'"; " . $table . " as a left join on (a.cid=b.cid ".$staffid.")
  1611. $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;
  1612. } else {
  1613. if (strlen ( $condition ) == 1 || empty ( $condition ))
  1614. $sql = "select count(*) as count from CLD_client as a " . $condition;
  1615. else
  1616. $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;
  1617. }
  1618. if (! empty ( $search ))
  1619. $sql = "select count(*) as count from CLD_client as a where 1 " . $condition;
  1620. if (! empty ( $tooltip )) {
  1621. $condition = str_replace ( "a.", "c.", $condition );
  1622. if ($tagSQL)
  1623. $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;
  1624. else
  1625. $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;
  1626. }
  1627. // echo $sql;
  1628. $query = Doo::db ()->query ( $sql );
  1629. $result = $query->fetch ();
  1630. return $result ['count'];
  1631. }
  1632. public function holidayGroup() {
  1633. Doo::loadModel ( 'staff' );
  1634. Doo::loadModel ( "holidayacman" );
  1635. Doo::loadModel ( 'L_category' );
  1636. $L_category = new L_category ();
  1637. $acman = new HACMan ();
  1638. $staff = new staff ();
  1639. $data ['staffList'] = $staff->find ( array (
  1640. 'select' => 'username,sid,wxid',
  1641. 'where' => 'cid!=1',
  1642. 'asArray' => true
  1643. ) );
  1644. $acmanlist = $acman->find ( array (
  1645. 'where' => 'type=0',
  1646. 'desc' => 'id',
  1647. 'asArray' => true
  1648. ) );
  1649. if (! empty ( $acmanlist )) {
  1650. foreach ( $acmanlist as $k => $v ) {
  1651. $acmanlist [$k] ['name'] = implode ( '->', explode ( ' ', $v ['name'] ) );
  1652. $category = explode ( ',', $v ['category'] );
  1653. $categoryname = array ();
  1654. if (! empty ( $category )) {
  1655. foreach ( $category as $key => $value ) {
  1656. $name = $L_category->getOne ( array (
  1657. 'where' => 'cid="' . $value . '"',
  1658. 'asArray' => TRUE
  1659. ) );
  1660. array_push ( $categoryname, $name ['title'] );
  1661. }
  1662. }
  1663. $acmanlist [$k] ['categoryname'] = implode ( ',', $categoryname );
  1664. }
  1665. }
  1666. // 获取办事处列表
  1667. $data ['category'] = $L_category->getCategory ();
  1668. $data ['acmanlist'] = $acmanlist;
  1669. $data ['staff'] = $this->staff;
  1670. $data ['memu'] = 'holiday';
  1671. $data ['noindexjs'] = 'noindexjs';
  1672. $this->render ( "/admin/admin_holidayGroup", $data );
  1673. }
  1674. public function addHolidayApprover() {
  1675. if (! isset ( $_POST ['title'] ) || empty ( $_POST ['title'] )) {
  1676. exit ( '请输入组名' );
  1677. }
  1678. if (! isset ( $_POST ['staff'] ) || empty ( $_POST ['staff'] )) {
  1679. exit ( '请选择成员' );
  1680. }
  1681. $idname = $name = $pinyinname = array ();
  1682. $stafflist = explode ( ',', $_POST ['staff'] );
  1683. foreach ( $stafflist as $k => $v ) {
  1684. $msg = explode ( ':', $v );
  1685. array_push ( $idname, $msg [0] );
  1686. array_push ( $name, $msg [1] );
  1687. array_push ( $pinyinname, $msg [2] );
  1688. }
  1689. Doo::loadModel ( "holidayacman" );
  1690. $acman = new HACMan ();
  1691. $acman->typename = $_POST ['title'];
  1692. $acman->idname = implode ( ',', $idname );
  1693. $acman->name = implode ( ' ', $name );
  1694. $acman->pinyinname = implode ( '|', $pinyinname );
  1695. $acman->type = 0;
  1696. $result = $acman->insert ();
  1697. if ($result) {
  1698. $acman2 = new HACMan ();
  1699. $acman2->type = $result;
  1700. $acman2->insert ();
  1701. Doo::loadModel ( 'holidaystaff' );
  1702. foreach ( $idname as $ik => $iv ) {
  1703. $hstaff = new HStaff ();
  1704. $hstaff->uid = $iv;
  1705. $hstaff->isadmin = 1;
  1706. $hstaff->update ();
  1707. }
  1708. }
  1709. return '/holidaygroup';
  1710. }
  1711. public function setHolidaySee() {
  1712. if (! isset ( $_POST ['groupid'] ) || empty ( $_POST ['groupid'] ) || ! is_numeric ( $_POST ['groupid'] )) {
  1713. exit ( '审批组id出错' );
  1714. }
  1715. $category = ! empty ( $_POST ['category'] ) ? implode ( ',', $_POST ['category'] ) : '';
  1716. Doo::loadModel ( 'holidayacman' );
  1717. $acman = new HACMan ();
  1718. $acman->id = $_POST ['groupid'];
  1719. $acman->category = $category;
  1720. $acman->update ();
  1721. return '/holidaygroup';
  1722. }
  1723. public function delHolidayGroup() {
  1724. if (! isset ( $_POST ['approvalid'] ) || empty ( $_POST ['approvalid'] ) || ! is_numeric ( $_POST ['approvalid'] )) {
  1725. exit ( '审批组id出错' );
  1726. }
  1727. Doo::loadModel ( 'holidayacman' );
  1728. $acman = new HACMan ();
  1729. $idname = $acman->getOne ( array (
  1730. 'where' => 'id=' . $_POST ['approvalid'],
  1731. 'asArray' => TRUE
  1732. ) );
  1733. $idname = explode ( ',', $idname ['idname'] );
  1734. $acman->id = $_POST ['approvalid'];
  1735. $acman->delete ();
  1736. // $acman2 = new HACMan();
  1737. // $acman2->type = $_POST['approvalid'];
  1738. // $acman2->delete();
  1739. // 删除管理员资格
  1740. $acman3 = new HACMan ();
  1741. foreach ( $idname as $k => $v ) {
  1742. $same = 0;
  1743. $approverlist = $acman3->find ( array (
  1744. 'where' => 'idname like "%' . $v . '%" and type=0',
  1745. 'asArray' => TRUE
  1746. ) );
  1747. if (! empty ( $approverlist )) {
  1748. foreach ( $approverlist as $ak => $av ) {
  1749. $aidname = explode ( ',', $av ['idname'] );
  1750. foreach ( $aidname as $ik => $iv ) {
  1751. if ($iv == $v) {
  1752. $same = 1;
  1753. break;
  1754. }
  1755. }
  1756. }
  1757. }
  1758. if ($same == 0) {
  1759. Doo::loadModel ( 'holidaystaff' );
  1760. $hstaff = new HStaff ();
  1761. $hstaff->uid = $v;
  1762. $hstaff->isadmin = 0;
  1763. $hstaff->update ();
  1764. }
  1765. }
  1766. return '/holidaygroup';
  1767. }
  1768. public function holidayCSGroup() {
  1769. Doo::loadModel ( 'staff' );
  1770. Doo::loadModel ( 'holidayacman' );
  1771. $acman = new HACMan ();
  1772. $staff = new staff ();
  1773. $approverlist = $acman->find ( array (
  1774. 'where' => 'type=0',
  1775. 'desc' => 'id',
  1776. 'asArray' => TRUE
  1777. ) );
  1778. if (! empty ( $approverlist )) {
  1779. foreach ( $approverlist as $k => $v ) {
  1780. $csman = $acman->getOne ( array (
  1781. 'where' => 'type=' . $v ['id'],
  1782. 'asArray' => TRUE
  1783. ) );
  1784. if (! empty ( $csman ['name'] )) {
  1785. $idname = explode ( ',', $csman ['idname'] );
  1786. $name = explode ( ' ', $csman ['name'] );
  1787. $pinyinname = explode ( '|', $csman ['pinyinname'] );
  1788. $csmsg = array ();
  1789. foreach ( $idname as $ik => $iv ) {
  1790. $csmsg [$ik] ['csidname'] = $iv;
  1791. $csmsg [$ik] ['csname'] = $name [$ik];
  1792. $csmsg [$ik] ['cspinyinname'] = $pinyinname [$ik];
  1793. }
  1794. $approverlist [$k] ['csmsg'] = $csmsg;
  1795. }
  1796. }
  1797. $data ['approverlist'] = $approverlist;
  1798. }
  1799. // 获取总部人员列表
  1800. $zongbu = $staff->getStaffByCid ( 12 );
  1801. $data ['zongbu'] = $zongbu;
  1802. // 获取办事处列表
  1803. Doo::loadModel ( 'L_category' );
  1804. $L_category = new L_category ();
  1805. $data ['category'] = $L_category->getCategory ();
  1806. $data ['memu'] = 'holiday';
  1807. $data ['noindexjs'] = 'noindexjs';
  1808. $this->render ( "/admin/admin_holidayGroup_cc", $data );
  1809. }
  1810. public function getStaffCategory() {
  1811. if (isset ( $_POST ['cid'] ) && is_numeric ( $_POST ['cid'] )) {
  1812. Doo::loadModel ( 'staff' );
  1813. $staff = new staff ();
  1814. $stafflist = $staff->getStaffByCid ( $_POST ['cid'] );
  1815. exit ( json_encode ( array (
  1816. 'code' => 200,
  1817. 'stafflist' => $stafflist
  1818. ) ) );
  1819. }
  1820. exit ( json_encode ( array (
  1821. 'code' => 400
  1822. ) ) );
  1823. }
  1824. public function addHolidayCS() {
  1825. if (! isset ( $_POST ['approvalid'] ) || empty ( $_POST ['approvalid'] ) || ! is_numeric ( $_POST ['approvalid'] )) {
  1826. exit ( '审批组出错' );
  1827. }
  1828. if (! isset ( $_POST ['cidstaff'] ) || empty ( $_POST ['cidstaff'] )) {
  1829. exit ( '抄送人出错' );
  1830. }
  1831. $cidstaff = explode ( ':', $_POST ['cidstaff'] );
  1832. Doo::loadModel ( 'holidayacman' );
  1833. $acman = new HACMan ();
  1834. $csmsg = $acman->getOne ( array (
  1835. 'where' => 'type=' . $_POST ['approvalid'],
  1836. 'asArray' => TRUE
  1837. ) );
  1838. $csidmsg = ! empty ( $csmsg ['idname'] ) ? $csmsg ['idname'] . ',' . $cidstaff [0] : $cidstaff [0];
  1839. $csnamemsg = ! empty ( $csmsg ['name'] ) ? $csmsg ['name'] . ' ' . $cidstaff [1] : $cidstaff [1];
  1840. $cspinyinnamemsg = ! empty ( $csmsg ['pinyinname'] ) ? $csmsg ['pinyinname'] . '|' . $cidstaff [2] : $cidstaff [2];
  1841. $acman->id = $csmsg ['id'];
  1842. $acman->idname = $csidmsg;
  1843. $acman->name = $csnamemsg;
  1844. $acman->pinyinname = $cspinyinnamemsg;
  1845. $acman->update ();
  1846. Doo::loadModel ( 'holidaystaff' );
  1847. $hstaff = new HStaff ();
  1848. $hstaffmsg = $hstaff->getOne ( array (
  1849. 'where' => 'uid=?',
  1850. 'param' => array (
  1851. $cidstaff [0]
  1852. ),
  1853. 'asArray' => TRUE
  1854. ) );
  1855. if (! empty ( $hstaffmsg ) && $hstaffmsg ['iscc'] == 0) {
  1856. $hstaff->uid = $cidstaff [0];
  1857. $hstaff->iscc = 1;
  1858. $hstaff->update ();
  1859. }
  1860. return '/hcsgroup';
  1861. }
  1862. public function delHolidayCS() {
  1863. if (! isset ( $_POST ['approvalid'] ) || empty ( $_POST ['approvalid'] ) || ! is_numeric ( $_POST ['approvalid'] )) {
  1864. exit ( '审批id出错' );
  1865. }
  1866. if (! isset ( $_POST ['cidstaff'] ) || empty ( $_POST ['cidstaff'] )) {
  1867. exit ( '抄送信息出错' );
  1868. }
  1869. $cidstaff = explode ( ':', $_POST ['cidstaff'] );
  1870. Doo::loadModel ( 'holidayacman' );
  1871. $acman = new HACMan ();
  1872. $csmsg = $acman->getOne ( array (
  1873. 'where' => 'type=' . $_POST ['approvalid'],
  1874. 'asArray' => TRUE
  1875. ) );
  1876. if (! empty ( $csmsg ['idname'] )) {
  1877. $idnamearr = explode ( ',', $csmsg ['idname'] );
  1878. foreach ( $idnamearr as $ik => $iv ) {
  1879. if ($iv == $cidstaff [0]) {
  1880. unset ( $idnamearr [$ik] );
  1881. break;
  1882. }
  1883. }
  1884. $csidmsg = implode ( ',', $idnamearr );
  1885. }
  1886. if (! empty ( $csmsg ['name'] )) {
  1887. $namearr = explode ( ' ', $csmsg ['name'] );
  1888. foreach ( $namearr as $nk => $nv ) {
  1889. if ($nv == $cidstaff [1]) {
  1890. unset ( $namearr [$nk] );
  1891. break;
  1892. }
  1893. }
  1894. $csnamemsg = implode ( ' ', $namearr );
  1895. }
  1896. if (! empty ( $csmsg ['pinyinname'] )) {
  1897. $pinyinnamearr = explode ( '|', $csmsg ['pinyinname'] );
  1898. foreach ( $pinyinnamearr as $pk => $pv ) {
  1899. if ($pv == $cidstaff [2]) {
  1900. unset ( $pinyinnamearr [$pk] );
  1901. break;
  1902. }
  1903. }
  1904. $cspinyinnamemsg = implode ( '|', $pinyinnamearr );
  1905. }
  1906. $acman->id = $csmsg ['id'];
  1907. if (isset ( $csidmsg )) {
  1908. $acman->idname = $csidmsg;
  1909. }
  1910. if (isset ( $csnamemsg )) {
  1911. $acman->name = $csnamemsg;
  1912. }
  1913. if (isset ( $cspinyinnamemsg )) {
  1914. $acman->pinyinname = $cspinyinnamemsg;
  1915. }
  1916. $acman->update ();
  1917. // 删除抄送员资格
  1918. $acman3 = new HACMan ();
  1919. $same = 0;
  1920. $approverlist = $acman3->find ( array (
  1921. 'where' => 'idname like "%' . $cidstaff [0] . '%" and type!=0',
  1922. 'asArray' => TRUE
  1923. ) );
  1924. if (! empty ( $approverlist )) {
  1925. foreach ( $approverlist as $ak => $av ) {
  1926. $aidname = explode ( ',', $av ['idname'] );
  1927. foreach ( $aidname as $ik => $iv ) {
  1928. if ($iv == $cidstaff [0]) {
  1929. $same = 1;
  1930. break;
  1931. }
  1932. }
  1933. }
  1934. }
  1935. if ($same == 0) {
  1936. Doo::loadModel ( 'holidaystaff' );
  1937. $hstaff = new HStaff ();
  1938. $hstaff->uid = $cidstaff [0];
  1939. $hstaff->iscc = 0;
  1940. $hstaff->update ();
  1941. }
  1942. return '/hcsgroup';
  1943. }
  1944. public function HolidayAdmin() {
  1945. Doo::loadModel ( 'staff' );
  1946. $staff = new staff ();
  1947. $staffList = $staff->find ( array (
  1948. 'select' => 'username,sid',
  1949. 'where' => 'cid!=1',
  1950. 'asArray' => true
  1951. ) );
  1952. Doo::loadModel ( 'holidayadmin' );
  1953. $admin = new HAdmin ();
  1954. $adminList = $admin->find ( array (
  1955. 'asArray' => TRUE
  1956. ) );
  1957. if (! empty ( $adminList )) {
  1958. foreach ( $adminList as $k => $v ) {
  1959. foreach ( $staffList as $sk => $sv ) {
  1960. if ($sv ['sid'] == $v ['uid']) {
  1961. array_splice ( $staffList, $sk, 1 );
  1962. break;
  1963. }
  1964. }
  1965. }
  1966. }
  1967. $data ['staffList'] = $staffList;
  1968. $data ['adminList'] = $adminList;
  1969. $data ['memu'] = 'holiday';
  1970. $data ['noindexjs'] = 'noindexjs';
  1971. $this->render ( "/admin/admin_holidayuser", $data );
  1972. }
  1973. public function addHolidayAdmin() {
  1974. if (! isset ( $_POST ['staff'] ) || empty ( $_POST ['staff'] )) {
  1975. exit ( '请选择管理人' );
  1976. }
  1977. Doo::loadModel ( 'holidayadmin' );
  1978. foreach ( $_POST ['staff'] as $k => $v ) {
  1979. $staffmsg = explode ( ':', $v );
  1980. $admin = new HAdmin ();
  1981. $admin->uid = $staffmsg [0];
  1982. $admin->username = $staffmsg [1];
  1983. $admin->insert ();
  1984. }
  1985. return '/holidayadmin';
  1986. }
  1987. public function delHolidayAdmin() {
  1988. if (! isset ( $_POST ['cidstaff'] ) || empty ( $_POST ['cidstaff'] )) {
  1989. exit ( '请选择管理人删除' );
  1990. }
  1991. Doo::loadModel ( 'holidayadmin' );
  1992. $admin = new HAdmin ();
  1993. $admin->id = $_POST ['cidstaff'];
  1994. $admin->delete ();
  1995. return '/holidayadmin';
  1996. }
  1997. // 检查年假是否过期并更新年假
  1998. private function updateAnnualLeave($staff) {
  1999. Doo::loadModel ( 'holidaystaff' );
  2000. $hstaff = new HStaff ();
  2001. $hstaffmsg = $hstaff->getOne ( array (
  2002. 'where' => 'uid=' . $staff ['sid'],
  2003. 'asArray' => TRUE
  2004. ) );
  2005. $hiredate = $staff ['hiredate'];
  2006. $hadyear = intval ( (time () - strtotime ( $hiredate )) / (86400 * 365) );
  2007. if ($hadyear != $hstaffmsg ['hadyear']) {
  2008. $hstaff->uid = $staff ['sid'];
  2009. $hstaff->hadyear = $hadyear;
  2010. $hstaff->yearnum = $hadyear == 0 ? 0 : (($hadyear < 10 && $hadyear >= 1) ? 5 : (($hadyear >= 10 && $hadyear < 20) ? 10 : 15));
  2011. $hstaff->update ();
  2012. }
  2013. }
  2014. }
  2015. ?>