AdminController.php 33 KB

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