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