AdminController.php 47 KB

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