InvoiceController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class InvoiceController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. public static $NEW = 0;
  10. public static $NEW2 = 0;
  11. private $INVOICEKEY="APPROVAL";
  12. function __construct() {
  13. if(isset($_COOKIE["staff"])){
  14. if(!empty($_COOKIE["staff"])){
  15. Doo::loadModel ( 'staff' );
  16. Doo::loadModel('verify');
  17. $verify=new verify();
  18. $staff = new staff ();
  19. Doo::loadModel("execute");
  20. $execute=new execute();
  21. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  22. $list=array();
  23. //判断角色的审批权限
  24. foreach ($verifyList as $key=>$value){
  25. $ver=json_decode($value['staff']);
  26. foreach ($ver as $k=>$v){
  27. if ($v[1]=='ROLE'){
  28. $roleList=json_decode($v[3]);
  29. foreach ($roleList as $t=>$g){
  30. $gList=explode("_", $g);
  31. array_push($list, $gList[0]);
  32. //print_r($list);
  33. }
  34. }else
  35. array_push($list, $v[0]);
  36. }
  37. }
  38. //判断执行人的审批权限
  39. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  40. $list2=array();
  41. foreach ($executeList as $key=>$value){
  42. $ver=json_decode($value['staff']);
  43. foreach ($ver as $k=>$v){
  44. array_push($list2, $v[0]);
  45. }
  46. }
  47. $eidList=file_get_contents("protected/config/execute/execute.ini");
  48. $eidList=array_filter(explode(",", $eidList));
  49. $this->executeId= array_merge($list2,$eidList);
  50. $this->verifyId=$list;
  51. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  52. ReceiptController::$NEW= $this->getReceiptCount();
  53. ReceiptController::$NEW2= $this->getExeCount();
  54. return "/";
  55. }
  56. }
  57. Doo::loadCore ( 'uri/DooUriRouter' );
  58. $router = new DooUriRouter ();
  59. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  60. if($routeRs['1']!="login"){
  61. header ( 'Content-Type:text/html;charset=utf-8' );
  62. @header ( "Location: /login" );
  63. }
  64. }
  65. function invoice(){
  66. $data['memu']="invoice";
  67. $data['staff']=$this->staff;
  68. $data['receiptMemu']='invoice';
  69. $data['verifyId']=$this->verifyId;
  70. $data['executeId']=$this->executeId;
  71. $this->render ( "/admin/invoice", $data );
  72. }
  73. function invoiceAdd(){
  74. Doo::loadModel('L_category');
  75. $lCategory=new L_category();
  76. $category=$lCategory->find(array('asArray'=>true));
  77. $data['category']=$category;
  78. $data['memu']="invoice";
  79. $data['staff']=$this->staff;
  80. $data['receiptMemu']='invoice';
  81. $data['verifyId']=$this->verifyId;
  82. $data['executeId']=$this->executeId;
  83. $this->render ( "/admin/invoiceAdd", $data );
  84. }
  85. function invoiceAddDo(){
  86. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  87. $invoiceType=$this->get_args('invoiceType')&&is_numeric($this->get_args('invoiceType'))?$this->get_args('invoiceType'):0;
  88. $doPost=$this->get_args('doPost')&&is_numeric($this->get_args('doPost'))?$this->get_args('doPost'):0;
  89. $invoicePrice=$this->get_args('invoicePrice')?$this->get_args('invoicePrice'):"";
  90. $invoiceElement=$this->get_args('invoiceElement')?$this->get_args('invoiceElement'):"";
  91. $invoiceTitle=$this->get_args('invoiceTitle')?$this->get_args('invoiceTitle'):"";
  92. $invoiceCompany=$this->get_args('invoiceCompany')?$this->get_args('invoiceCompany'):"";
  93. $TIN=$this->get_args('TIN')?$this->get_args('TIN'):"";
  94. $address=$this->get_args('address')?$this->get_args('address'):"";
  95. $phone=$this->get_args('phone')?$this->get_args('phone'):"";
  96. $bank=$this->get_args('bank')?$this->get_args('bank'):"";
  97. $bankAccount=$this->get_args('bankAccount')?$this->get_args('bankAccount'):"";
  98. $recipients=$this->get_args('recipients')?$this->get_args('recipients'):"";
  99. $recipientsPhone=$this->get_args('recipientsPhone')?$this->get_args('recipientsPhone'):"";
  100. $recipientsAddress=$this->get_args('recipientsAddress')?$this->get_args('recipientsAddress'):"";
  101. $mailItems=$this->get_args('mailItems')?$this->get_args('mailItems'):"";
  102. $remark=$this->get_args('remark')?$this->get_args('remark'):"";
  103. if(!empty($cid)&&!empty($invoicePrice)&&!empty($invoiceElement)){
  104. Doo::loadModel('invoice');
  105. $invoice=new invoice();
  106. Doo::loadModel('L_category');
  107. $lCategory=new L_category();
  108. Doo::loadModel('invoiceManage');
  109. $invoiceManage=new invoiceManage();
  110. $categoryDetil=$lCategory->getOne(array('SELECT'=>'title','where'=>'cid='.$cid,'asArray'=>true));
  111. $invoiceManageDetail=$invoiceManage->getOne(array('SELECT'=>'title','where'=>'mold="发票审批"','asArray'=>true));
  112. $invoice->cid=$cid;
  113. $invoice->categoryName=$categoryDetil['title'];
  114. $invoice->invoiceElement=$invoiceElement;
  115. $invoice->invoicePrice=$invoicePrice;
  116. $invoice->invoiceType=$invoiceType;
  117. if ($invoiceType==0)
  118. $invoice->invoiceTitle=$invoiceTitle;
  119. elseif ($invoiceType==1){
  120. $invoice->invoiceCompany=$invoiceCompany;
  121. $invoice->TIN=$TIN;
  122. $invoice->address=$address;
  123. $invoice->phone=$phone;
  124. $invoice->bank=$bank;
  125. $invoice->bankAccount=$bankAccount;
  126. }
  127. $invoice->doPost=$doPost;
  128. if ($doPost==1){
  129. $invoice->recipients=$recipients;
  130. $invoice->recipientsPhone=$recipientsPhone;
  131. $invoice->recipientsAddress=$recipientsAddress;
  132. $invoice->mailItems=$mailItems;
  133. }
  134. $invoice->status=1;
  135. $invoice->invoiceSerial="#F".date("Ymd").mt_rand(1000,9999);
  136. $invoice->date=date("Y-m-d H:i:s");
  137. $invoice->updateTime=date("Y-m-d H:i:s");
  138. $invoice->sid=$this->staff[0]['sid'];
  139. $invoice->userName=$this->staff[0]['username'];
  140. $invoice->invoiceManage=$invoiceManageDetail['staff'];
  141. $staffId=$a=json_decode($invoiceManageDetail['staff']);
  142. $invoice->pendingApprovals=$staffId[0][0];
  143. $invoice->remark=$remark;
  144. $invoice->insert();
  145. }
  146. return "/invoice";
  147. }
  148. function invoiceApproval(){
  149. Doo::loadModel('invoice');
  150. $invoice=new invoice();
  151. Doo::loadModel('invoiceManage');
  152. $invoiceManage=new invoiceManage();
  153. Doo::loadClass('XDeode');
  154. $XDeode=new XDeode(5);
  155. Doo::loadModel('staff');
  156. $staff=new staff();
  157. $invoiceList=$invoice->find(array('where'=>'status=1 and pendingApprovals='.$this->staff[0]['sid'],'asArray'=>true));
  158. foreach ($invoiceList as $key=>$value){
  159. $invoiceList[$key]['iidKey']=$XDeode->encode($value['iid']);//base64_encode($value['iid']);
  160. $lastApprover=json_decode($value['processApprovals'],true);
  161. if (!empty($lastApprover)){
  162. $lastApproverKey=array_keys($lastApprover);
  163. $lastApprover=end($lastApprover);
  164. $staffDetail=$staff->getOne(array('where'=>'sid='.end($lastApproverKey),'asArray'=>true));
  165. $lastApprover['username']=$staffDetail['username'];
  166. }
  167. $invoiceList[$key]['lastApprover']=$lastApprover;
  168. }
  169. $data['invoiceList']=$invoiceList;
  170. $data['memu']="invoice";
  171. $data['staff']=$this->staff;
  172. $data['receiptMemu']='invoiceApproval';
  173. $data['verifyId']=$this->verifyId;
  174. $data['executeId']=$this->executeId;
  175. $this->render ( "/admin/invoiceApproval", $data );
  176. }
  177. function invoiceDetail(){
  178. Doo::loadClass('XDeode');
  179. $XDeode=new XDeode(5);
  180. $iid=isset($this->params['iid'])?$this->params['iid']:"";
  181. $iid=$XDeode->decode($iid);//base64_decode($iid);
  182. if (!is_numeric($iid))
  183. die('illegal request');
  184. Doo::loadModel('invoice');
  185. $invoice=new invoice();
  186. //Doo::loadModel('invoiceManage');
  187. //$invoiceManage=new invoiceManage();
  188. $invoiceDetail=$invoice->getOne(array('where'=>'status=1 and pendingApprovals='.$this->staff[0]['sid'].' and iid='.$iid,'asArray'=>true));
  189. //$invoiceManageDetail=$invoiceManage->getOne(array('SELECT'=>'title','where'=>'mold="发票审批"','asArray'=>true));
  190. //$a=json_decode($invoiceManageDetail['staff']);
  191. $data['invoiceDetail']=$invoiceDetail;
  192. $data['INVOICEKEY']=$this->authcode($invoiceDetail['iid'],'');
  193. $data['memu']="invoice";
  194. $data['staff']=$this->staff;
  195. $data['receiptMemu']='invoiceApproval';
  196. $data['verifyId']=$this->verifyId;
  197. $data['executeId']=$this->executeId;
  198. $this->render ( "/admin/invoiceApprovalDetail", $data );
  199. }
  200. function invoiceApprovalDo(){
  201. $iid=$this->get_args('invoiceKey')?$this->get_args('invoiceKey'):"";
  202. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  203. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  204. $iid=$this->authcode($iid);
  205. if (!is_numeric($iid))
  206. die('illegal request');
  207. if (!empty($iid)&&!empty($status)&&!empty($opinion)){
  208. if (!($status==2||$status==3||$status==4))
  209. die('illegal request');
  210. Doo::loadModel('invoice');
  211. $invoice=new invoice();
  212. $invoiceDetail=$invoice->getOne(array('where'=>'status=1 and iid='.$iid.' and pendingApprovals='.$this->staff[0]['sid'],'asArray'=>true));
  213. if (empty($invoiceDetail))
  214. die('illegal request');
  215. $processApprovals=json_decode($invoiceDetail['processApprovals'],true);
  216. $invoiceManage=json_decode($invoiceDetail['invoiceManage'],true);
  217. if ($status==3){
  218. $invoice->status=$status;
  219. //操作日志
  220. }else{
  221. if(empty($processApprovals)){//记录下一个IDKEY
  222. $processApprovals=array($this->staff[0]['sid']=>array('date'=>date("Y-m-d H:i:s"),'opinion'=>$opinion,'status'=>$status));
  223. if ($status!=4&&isset($invoiceManage[1]))
  224. $invoice->pendingApprovals=$invoiceManage[1][0];
  225. $invoice->processApprovals=json_encode($processApprovals);
  226. }else{
  227. $processApprovals[$this->staff[0]['sid']]=array('date'=>date("Y-m-d H:i:s"),'opinion'=>$opinion,'status'=>$status);
  228. $pendingApprovals=0;
  229. foreach ($invoiceManage as $key=>$value){
  230. if ($value[0]==$this->staff[0]['sid']){
  231. if (isset($invoiceManage[$key+1]))
  232. $pendingApprovals=$invoiceManage[$key+1][0];
  233. break;
  234. }
  235. }
  236. if($status!=4&&!empty($pendingApprovals))
  237. $invoice->pendingApprovals=$pendingApprovals;
  238. $invoice->processApprovals=json_encode($processApprovals);
  239. }
  240. if(count($processApprovals)==count($invoiceManage)&&$status!=4){
  241. $invoice->status=$status;
  242. $invoice->pendingApprovals=0;
  243. }elseif ($status==4)
  244. $invoice->status=$status;
  245. }
  246. $invoice->updateTime=date("Y-m-d H:i:s");
  247. $invoice->update(array('where'=>'iid='.$iid));//print_r($processApprovals);
  248. return '/invoiceApproval';
  249. }
  250. }
  251. private function getExeCount(){
  252. Doo::loadModel('receipt');
  253. $receipt=new receipt();
  254. $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and executeStaff NOT LIKE \'%'.$this->staff[0]['sid'].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  255. return count($receiptList);
  256. }
  257. private function getReceiptCount(){
  258. $status=2;
  259. $year=date('Y');
  260. Doo::loadModel('receipt');
  261. $receipt=new receipt();
  262. Doo::loadModel('verify');
  263. $dateCondition=" and Year(date) =".$year;
  264. $approvalCondition=' and nowStaff like "%'.$this->staff[0]['sid'].'%" ';
  265. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  266. return count($receiptList);
  267. }
  268. function _GetFileEXT($filename) {
  269. $pics = explode ( '.', $filename );
  270. $num = count ( $pics );
  271. return $pics [$num - 1];
  272. }
  273. /**
  274. * 获取get或者POST值
  275. * @param string $name 属性名称
  276. * @return fixed 值
  277. */
  278. function get_args($name) {
  279. if (isset ( $_GET [$name] )) {
  280. if (is_array ( $_GET [$name] ))
  281. return $_GET [$name];
  282. else
  283. return addslashes ( $_GET [$name] );
  284. } elseif (isset ( $_POST [$name] )) {
  285. if (is_array ( $_POST [$name] ))
  286. return $_POST [$name];
  287. else
  288. return addslashes ( $_POST [$name] );
  289. } else
  290. return false;
  291. }
  292. /**
  293. * 加密或解密指定字符串
  294. * @param string $string 要加密或解密的字符串
  295. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  296. * @param string $key 加解密的key
  297. * @param $expiry 超时值
  298. * */
  299. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  300. $ckey_length = 4;
  301. if (! $key) {
  302. $key = $this->INVOICEKEY;
  303. }
  304. $key = md5 ( $key );
  305. $keya = md5 ( substr ( $key, 0, 16 ) );
  306. $keyb = md5 ( substr ( $key, 16, 16 ) );
  307. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  308. $cryptkey = $keya . md5 ( $keya . $keyc );
  309. $key_length = strlen ( $cryptkey );
  310. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  311. $string_length = strlen ( $string );
  312. $result = '';
  313. $box = range ( 0, 255 );
  314. $rndkey = array ();
  315. for($i = 0; $i <= 255; $i ++) {
  316. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  317. }
  318. for($j = $i = 0; $i < 256; $i ++) {
  319. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  320. $tmp = $box [$i];
  321. $box [$i] = $box [$j];
  322. $box [$j] = $tmp;
  323. }
  324. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  325. $a = ($a + 1) % 256;
  326. $j = ($j + $box [$a]) % 256;
  327. $tmp = $box [$a];
  328. $box [$a] = $box [$j];
  329. $box [$j] = $tmp;
  330. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  331. }
  332. if ($operation == 'DECODE') {
  333. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  334. return substr ( $result, 26 );
  335. } else {
  336. return '';
  337. }
  338. } else {
  339. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  340. }
  341. }
  342. }
  343. class ReceiptController{
  344. public static $NEW = 0;
  345. public static $NEW2 = 0;
  346. }
  347. ?>