AdminController.php 67 KB

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