AdminController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  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 ajaxRoleStaff(){
  662. $name=$this->get_args('name')?$this->get_args('name'):"";
  663. Doo::loadModel('staff');
  664. $staff=new staff();
  665. $staffList=$staff->find(array('select'=>'username,sid,avatar','where'=>'username != "'.$name.'" and username !="admin"','asArray'=>true));
  666. $html='';
  667. foreach ($staffList as $key=>$value){
  668. $html.='<option value='.$value['sid'].'_'.$value['username'].'>'.$value['username'].'</option>';
  669. }
  670. echo json_encode(array("success"=>true,'html'=>$html));die;
  671. }
  672. function loadCVS(){
  673. Doo::loadModel('longle');
  674. $longle=new longle();
  675. $list=$longle->find(array('select'=>'key_num','asArray' => TRUE));
  676. $file = fopen(DOO::conf()->SITE_PATH."upload/key2.csv",'r');
  677. while ($data = fgetcsv($file)) {
  678. $goods_list[$data[0]] = $data[1] ;
  679. }
  680. fclose($file);
  681. $sqlArray=array();
  682. $sql='UPDATE CLD_longle SET SerialNumber = CASE key_num ';
  683. foreach($list as $key=>$value){
  684. if(array_key_exists($value['key_num'],$goods_list)){
  685. //echo $value['key_num'].'-'.$goods_list[$value['key_num']].'<br/>';
  686. //$longle->SerialNumber=$goods_list[$value['key_num']];
  687. //$longle->update(array('where'=>'key_num="'.$value['key_num'].'"'));
  688. $sql.=' WHEN "'.$value['key_num'].'" THEN "'.$goods_list[$value['key_num']].'" ';
  689. array_push($sqlArray, '"'.$value['key_num'].'"');
  690. unset($goods_list[$value['key_num']]);
  691. }
  692. }
  693. $sql.='END WHERE key_num IN ('.implode(',', $sqlArray).')';
  694. echo $sql.'<br/>--------------------------------<br/>';
  695. foreach ($goods_list as $key=>$value){
  696. echo $key.','.$value.'<br/>';
  697. }
  698. }
  699. private function getRandChar($length){
  700. $str = null;
  701. $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
  702. $max = strlen($strPol)-1;
  703. for($i=0;$i<$length;$i++){
  704. $str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
  705. }
  706. return $str;
  707. }
  708. private function getReceiptCount(){
  709. $status=2;
  710. $year=date('Y');
  711. Doo::loadModel('receipt');
  712. $receipt=new receipt();
  713. Doo::loadModel('verify');
  714. $verify=new verify();
  715. //user verify ID
  716. $vidList=array();
  717. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'\"%"','asArray'=>true));
  718. foreach ($verifyDetail as $key=>$value){
  719. array_push($vidList, $value['vid']);
  720. }
  721. $vid=implode(",", $vidList);
  722. if(empty($verifyDetail))
  723. $vid=0;
  724. $dateCondition=" and Year(date) =".$year;
  725. $approvalCondition=' and verifyStaff not like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  726. $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  727. return count($receiptList);
  728. }
  729. /**
  730. * 格式化excel文件为数组
  731. * @param unknown_type $file_url
  732. * @param unknown_type $mcid
  733. */
  734. function _format_excel_to_array($file_url = "") {
  735. if (! file_exists ( $file_url ))
  736. return array ();
  737. Doo::loadClass ( 'PHPExcel' );
  738. $PHPExcel = new PHPExcel ();
  739. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  740. if (! $PHPReader->canRead ( $file_url )) {
  741. $PHPReader = new PHPExcel_Reader_Excel5 ();
  742. if (! $PHPReader->canRead ( $file_url )) {
  743. echo 'no Excel';
  744. return;
  745. }
  746. }
  747. $PHPExcel = $PHPReader->load ( $file_url );
  748. /**读取excel文件中的第一个工作表*/
  749. $currentSheet = $PHPExcel->getSheet ( 0 );
  750. /**取得最大的列号*/
  751. $allColumn = $currentSheet->getHighestColumn ();
  752. /**取得一共有多少行*/
  753. $allRow = $currentSheet->getHighestRow ();
  754. $excel_array = array ();
  755. for($currentRow = 2; $currentRow <= $allRow; $currentRow ++) {
  756. $excel_column = array ();
  757. //后期改进
  758. if($allColumn=='AM')
  759. $allColumn='Z';
  760. /**从第A列开始输出*/
  761. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  762. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  763. /**ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312',*/
  764. $val = "'" . addslashes ( $val ) . "'";
  765. if ($currentColumn == 'A')
  766. $excel_column ['key_num'] = $val;
  767. elseif ($currentColumn == 'C')
  768. $excel_column ['product'] = $val;
  769. elseif ($currentColumn == 'D'){
  770. $val=str_replace("'","",$val);
  771. $excel_column ['make_day'] = $this->excelTime($val);
  772. }elseif($currentColumn == 'E'){
  773. $val=str_replace("'","",$val);
  774. $excel_column ['alloted_time'] = $this->excelTime($val);
  775. }elseif($currentColumn == 'F'){
  776. $val=str_replace("'","",$val);
  777. $excel_column ['version'] = $val;
  778. }elseif ($currentColumn == 'B'){
  779. $val=str_replace("'","",$val);
  780. $excel_column ['SerialNumber'] = $val;
  781. }
  782. }
  783. array_push ( $excel_array, $excel_column );
  784. }
  785. return $excel_array;
  786. }
  787. function excelTime($date, $time = false)
  788. {
  789. if (function_exists ( 'GregorianToJD' ))
  790. {
  791. if (is_numeric ( $date ))
  792. {
  793. $jd = GregorianToJD ( 1, 1, 1970 );
  794. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  795. $date = explode ( '/', $gregorian );
  796. $date_str = str_pad ( $date [2], 4, '0', STR_PAD_LEFT ) . "-" .
  797. str_pad ( $date [0], 2, '0', STR_PAD_LEFT ) . "-" .
  798. str_pad ( $date [1], 2, '0', STR_PAD_LEFT ) . ($time ? " 00:00:00" : '');
  799. return $date_str;
  800. }
  801. } else
  802. {
  803. $date = $date > 25568 ? $date + 1 : 25569;
  804. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  805. $ofs = (70 * 365 + 17 + 2) * 86400;
  806. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  807. }
  808. return $date;
  809. }
  810. function _GetFileEXT($filename) {
  811. $pics = explode ( '.', $filename );
  812. $num = count ( $pics );
  813. return $pics [$num - 1];
  814. }
  815. /**
  816. * 获取get或者POST值
  817. * @param string $name 属性名称
  818. * @return fixed 值
  819. */
  820. function get_args($name) {
  821. if (isset ( $_GET [$name] )) {
  822. if (is_array ( $_GET [$name] ))
  823. return $_GET [$name];
  824. else {
  825. return addslashes ( $_GET [$name] );
  826. //return $_GET [$name] ;
  827. }
  828. } elseif (isset ( $_POST [$name] )) {
  829. if (is_array ( $_POST [$name] ))
  830. return $_POST [$name];
  831. else {
  832. return addslashes ( $_POST [$name] );
  833. //return $_POST [$name];
  834. }
  835. } else {
  836. return false;
  837. }
  838. }
  839. function get_previous($on_page = 1) {
  840. return $on_page != 0 ? $on_page - 1 : $on_page;
  841. }
  842. /**
  843. * 获得分页数据
  844. * @param unknown_type $table
  845. * @param unknown_type $condition
  846. * @param unknown_type $on_page
  847. * @param unknown_type $page_size
  848. */
  849. function get_Tpage($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "",$tagSQL) {
  850. $page_c = "";
  851. $page ['previous'] = $this->get_previous ( $on_page );
  852. $page ['on_page'] = $on_page;
  853. $total_count = $this->get_table_Tcount ( $table, $condition,$tagSQL );
  854. $total = intval ( $total_count / $page_size );
  855. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  856. $page ['total_data'] = $total_count;
  857. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  858. $i = 1;
  859. $page_max = 1;
  860. if ($on_page > 10) {
  861. $page_max = intval ( $on_page / 10 ) + 1;
  862. $i = intval ( $on_page / 10 ) * 10 - 1;
  863. }
  864. $page ['page'] = $page_c;
  865. $page ['lower'] = (-- $on_page) * $page_size;
  866. return $page;
  867. }
  868. /**
  869. * 获得分页数据
  870. * @param unknown_type $table
  871. * @param unknown_type $condition
  872. * @param unknown_type $on_page
  873. * @param unknown_type $page_size
  874. */
  875. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page",$staffid="",$search,$tooltip,$cateid,$tagSQL) {
  876. $page_c = "";
  877. $page ['previous'] = $this->get_previous ( $on_page );
  878. $page ['on_page'] = $on_page;
  879. $total_count = $this->get_table_count ( $table, $condition ,$staffid,$search,$tooltip,$cateid,$tagSQL);
  880. $total = intval ( $total_count / $page_size );
  881. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  882. $page ['total_data'] = $total_count;
  883. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  884. $i = 1;
  885. $page_max = 1;
  886. if ($on_page > 10) {
  887. $page_max = intval ( $on_page / 10 ) + 1;
  888. $i = intval ( $on_page / 10 ) * 10 - 1;
  889. }
  890. for(; $i <= $page ['total_page']; $i ++) {
  891. if ($i == $on_page) {
  892. if ($other == "page")
  893. $page_c .= '<a href="javascript:void(0);" class="current">' . $i . '</a>';
  894. else
  895. $page_c .= '&nbsp;<span class="current">' . $i . '</span>&nbsp;';
  896. } else if ($other == "page")
  897. $page_c .= '<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>';
  898. else
  899. $page_c .= '&nbsp;<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>&nbsp;';
  900. if ($i == (10 * $page_max))
  901. break;
  902. }
  903. $page ['page'] = $page_c;
  904. $page ['lower'] = (-- $on_page) * $page_size;
  905. return $page;
  906. }
  907. /**
  908. * 获取总页数
  909. * @param unknown_type $table
  910. * @param unknown_type $condition
  911. */
  912. public function get_table_Tcount($table = "", $condition = "",$tagSQL) {
  913. if ($tagSQL)
  914. $sql = "select count(*) as count from CLD_tagCompanyNexus as a left join CLD_company as b on (a.company=b.cid ) where ".$condition ;
  915. else
  916. $sql = "select count(*) as count from CLD_company where " . $condition ;
  917. $query = Doo::db ()->query ( $sql );
  918. $result = $query->fetch ();
  919. return $result ['count'];
  920. }
  921. /**
  922. * 获取总页数
  923. * @param unknown_type $table
  924. * @param unknown_type $condition
  925. */
  926. public function get_table_count($table = "", $condition = "",$staffid="",$search,$tooltip,$cateid,$tagSQL) {
  927. //$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  928. //echo $staffid;die;
  929. //
  930. if (!empty($staffid)){
  931. //$staffid="and a.sid= '".$staffid."'"; " . $table . " as a left join on (a.cid=b.cid ".$staffid.")
  932. $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 ;
  933. }else{
  934. if(strlen($condition)==1||empty($condition))
  935. $sql = "select count(*) as count from CLD_client as a ".$condition;
  936. else
  937. $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;
  938. }
  939. if(!empty($search))
  940. $sql = "select count(*) as count from CLD_client as a where 1 ".$condition ;
  941. if(!empty($tooltip)){
  942. $condition=str_replace("a.","c.",$condition);
  943. if ($tagSQL)
  944. $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 ;
  945. else
  946. $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 ;
  947. }
  948. //echo $sql;
  949. $query = Doo::db ()->query ( $sql );
  950. $result = $query->fetch ();
  951. return $result ['count'];
  952. }
  953. }
  954. ?>