InvoiceController.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. private $INVOICEKEY = "APPROVAL";
  12. function __construct() {
  13. if (isset ( $_COOKIE ["staff"] )) {
  14. if (! empty ( $_COOKIE ["staff"] )) {
  15. Doo::loadModel ( 'staff' );
  16. $staff = new staff ();
  17. Doo::loadModel("invoiceManage");
  18. $invoiceManage=new invoiceManage();
  19. //$invoiceManage
  20. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  21. return "/";
  22. }
  23. }
  24. Doo::loadCore ( 'uri/DooUriRouter' );
  25. $router = new DooUriRouter ();
  26. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  27. if ($routeRs ['1'] != "login") {
  28. header ( 'Content-Type:text/html;charset=utf-8' );
  29. @header ( "Location: /login" );
  30. }
  31. }
  32. function invoice() {
  33. Doo::loadModel ( 'invoice' );
  34. $invoice = new invoice ();
  35. $pendingInvoice = $invoice->getPendingByInvoice ();
  36. $data ['pendingInvoice'] = $pendingInvoice;
  37. $data ['memu'] = "invoice";
  38. $data ['staff'] = $this->staff;
  39. $data ['receiptMemu'] = 'invoice';
  40. $this->render ( "/admin/invoice", $data );
  41. }
  42. function invoiceAdd() {
  43. Doo::loadModel ( 'L_category' );
  44. $lCategory = new L_category ();
  45. $category = $lCategory->find ( array (
  46. 'asArray' => true
  47. ) );
  48. $data ['category'] = $category;
  49. $data ['memu'] = "invoice";
  50. $data ['staff'] = $this->staff;
  51. $data ['receiptMemu'] = 'invoice';
  52. $this->render ( "/admin/invoiceAdd", $data );
  53. }
  54. /**
  55. * 提交一份开票申请,并记录下操作日志
  56. *
  57. * @since 1.0.0
  58. * @var integer cid 办事处ID
  59. * @var integer invoiceType 发票类型
  60. * @var integer doPost 是否邮寄
  61. * @var integer invoicePrice 开票金额
  62. * @var string invoiceElement 开票内容
  63. * @var string invoiceTitle 发票抬头
  64. * @var string invoiceCompany 单位名称
  65. * @var string TIN 纳税人识别码
  66. * @var string address 注册地址
  67. * @var string phone 注册电话
  68. * @var string bank 开户银行
  69. * @var string bankAccount 银行账户
  70. * @var string recipients 收件人
  71. * @var string recipientsPhone 收件人手机/电话
  72. * @var string recipientsAddress 收件地址
  73. * @var string mailItems 邮寄物品
  74. * @var string remark 备注
  75. * @return string 返回跳转开票主页路径
  76. */
  77. function invoiceAddDo() {
  78. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  79. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  80. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  81. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  82. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  83. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  84. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  85. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  86. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  87. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  88. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  89. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  90. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  91. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  92. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  93. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  94. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  95. if (! empty ( $cid ) && ! empty ( $invoicePrice ) && ! empty ( $invoiceElement )) {
  96. Doo::loadModel ( 'invoice' );
  97. $invoice = new invoice ();
  98. Doo::loadModel ( 'L_category' );
  99. $lCategory = new L_category ();
  100. Doo::loadModel ( 'invoiceManage' );
  101. $invoiceManage = new invoiceManage ();
  102. Doo::loadModel ( 'invoiceOperationLog' );
  103. $invoiceOperationLog = new invoiceOperationLog ();
  104. $categoryDetil = $lCategory->getOne ( array (
  105. 'SELECT' => 'title',
  106. 'where' => 'cid=' . $cid,
  107. 'asArray' => true
  108. ) );
  109. $invoiceManageDetail = $invoiceManage->getOne ( array (
  110. 'SELECT' => 'title',
  111. 'where' => 'mold="发票审批"',
  112. 'asArray' => true
  113. ) );
  114. $invoice->cid = $cid;
  115. $invoice->categoryName = $categoryDetil ['title'];
  116. $invoice->invoiceElement = $invoiceElement;
  117. $invoice->invoicePrice = $invoicePrice;
  118. $invoice->invoiceType = $invoiceType;
  119. if ($invoiceType == 0)
  120. $invoice->invoiceTitle = $invoiceTitle;
  121. elseif ($invoiceType == 1) {
  122. $invoice->invoiceCompany = $invoiceCompany;
  123. $invoice->TIN = $TIN;
  124. $invoice->address = $address;
  125. $invoice->phone = $phone;
  126. $invoice->bank = $bank;
  127. $invoice->bankAccount = $bankAccount;
  128. }
  129. $invoice->doPost = $doPost;
  130. if ($doPost == 1) {
  131. $invoice->recipients = $recipients;
  132. $invoice->recipientsPhone = $recipientsPhone;
  133. $invoice->recipientsAddress = $recipientsAddress;
  134. $invoice->mailItems = $mailItems;
  135. }
  136. $invoice->status = 1;
  137. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  138. $invoice->date = date ( "Y-m-d H:i:s" );
  139. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  140. $invoice->sid = $this->staff [0] ['sid'];
  141. $invoice->userName = $this->staff [0] ['username'];
  142. $invoice->invoiceManage = $invoiceManageDetail ['staff'];
  143. $staffId = $a = json_decode ( $invoiceManageDetail ['staff'] );
  144. $invoice->pendingApprovals = $staffId [0] [0];
  145. $invoice->remark = $remark;
  146. $iid = $invoice->insert ();
  147. $item = array (
  148. 'date' => date ( "Y-m-d H:i:s" ),
  149. 'operation' => "创建",
  150. 'status' => 1,
  151. 'img' => $this->staff [0] ['avatar'],
  152. 'username' => $this->staff [0] ['username'],
  153. 'uid' => $this->staff [0] ['sid'],
  154. 'category' => $this->staff [0] ['category'],
  155. 'iid' => $iid
  156. );
  157. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  158. $item = array (
  159. 'date' => date ( "Y-m-d H:i:s" ),
  160. 'operation' => "提交审批",
  161. 'status' => 1,
  162. 'img' => $this->staff [0] ['avatar'],
  163. 'username' => $this->staff [0] ['username'],
  164. 'uid' => $this->staff [0] ['sid'],
  165. 'category' => $this->staff [0] ['category'],
  166. 'iid' => $iid
  167. );
  168. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  169. }
  170. return "/invoice";
  171. }
  172. function invoiceApproval() {
  173. Doo::loadModel ( 'invoice' );
  174. $invoice = new invoice ();
  175. Doo::loadClass ( 'XDeode' );
  176. $XDeode = new XDeode ( 5 );
  177. Doo::loadModel ( 'staff' );
  178. $staff = new staff ();
  179. $invoiceList = $invoice->find ( array (
  180. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  181. 'desc' => 'iid',
  182. 'asArray' => true
  183. ) );
  184. foreach ( $invoiceList as $key => $value ) {
  185. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  186. $lastApprover = json_decode ( $value ['processApprovals'], true );
  187. if (! empty ( $lastApprover )) {
  188. $lastApproverKey = array_keys ( $lastApprover );
  189. $lastApprover = end ( $lastApprover );
  190. $staffDetail = $staff->getOne ( array (
  191. 'where' => 'sid=' . end ( $lastApproverKey ),
  192. 'asArray' => true
  193. ) );
  194. $lastApprover ['username'] = $staffDetail ['username'];
  195. }
  196. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  197. }
  198. $data ['invoiceList'] = $invoiceList;
  199. $data ['memu'] = "invoice";
  200. $data ['staff'] = $this->staff;
  201. $data ['receiptMemu'] = 'invoiceApproval';
  202. $this->render ( "/admin/invoiceApproval", $data );
  203. }
  204. function invoiceDetail() {
  205. Doo::loadClass ( 'XDeode' );
  206. $XDeode = new XDeode ( 5 );
  207. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  208. $iid = $XDeode->decode ( $iid );
  209. if (! is_numeric ( $iid ))
  210. die ( 'illegal request' );
  211. Doo::loadModel ( 'invoice' );
  212. $invoice = new invoice ();
  213. Doo::loadModel ( 'invoiceOperationLog' );
  214. $invoiceOperationLog = new invoiceOperationLog ();
  215. $invoiceDetail = $invoice->getOne ( array (
  216. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  217. 'asArray' => true
  218. ) );
  219. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  220. $data ['invoiceDetail'] = $invoiceDetail;
  221. $data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  222. $data ['INVOICEKEY'] = $this->authcode ( $invoiceDetail ['iid'], '' );
  223. $data ['memu'] = "invoice";
  224. $data ['staff'] = $this->staff;
  225. $data ['receiptMemu'] = 'invoiceApproval';
  226. $this->render ( "/admin/invoiceApprovalDetail", $data );
  227. }
  228. /**
  229. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  230. *
  231. * @since 1.0.0
  232. * @var integer iid 开票ID 已加密
  233. * @var integer status 发票审批状态
  234. * @var integer opintion 审批发票的意见
  235. * @return string 如操作成功返回审批首页
  236. */
  237. function invoiceApprovalDo() {
  238. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  239. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  240. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  241. $iid = $this->authcode ( $iid );
  242. if (! is_numeric ( $iid ))
  243. die ( 'illegal request' );
  244. if (! empty ( $iid ) && ! empty ( $status ) && ! empty ( $opinion )) {
  245. if (! ($status == 2 || $status == 3 || $status == 4))
  246. die ( 'illegal request' );
  247. Doo::loadModel ( 'invoice' );
  248. $invoice = new invoice ();
  249. Doo::loadModel ( 'invoiceOperationLog' );
  250. $invoiceOperationLog = new invoiceOperationLog ();
  251. $invoiceDetail = $invoice->getOne ( array (
  252. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  253. 'asArray' => true
  254. ) );
  255. if (empty ( $invoiceDetail ))
  256. die ( 'illegal request' );
  257. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  258. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  259. if ($status == 3) {
  260. $invoice->status = $status;
  261. $item = array (
  262. 'operation' => "退回"
  263. );
  264. } else {
  265. if (empty ( $processApprovals )) {
  266. $processApprovals = array (
  267. $this->staff [0] ['sid'] => array (
  268. 'date' => date ( "Y-m-d H:i:s" ),
  269. 'opinion' => $opinion,
  270. 'status' => $status
  271. )
  272. );
  273. if ($status != 4 && isset ( $invoiceManage [1] ))
  274. $invoice->pendingApprovals = $invoiceManage [1] [0];
  275. $invoice->processApprovals = json_encode ( $processApprovals );
  276. } else {
  277. $processApprovals [$this->staff [0] ['sid']] = array (
  278. 'date' => date ( "Y-m-d H:i:s" ),
  279. 'opinion' => $opinion,
  280. 'status' => $status
  281. );
  282. $pendingApprovals = 0;
  283. foreach ( $invoiceManage as $key => $value ) {
  284. if ($value [0] == $this->staff [0] ['sid']) {
  285. if (isset ( $invoiceManage [$key + 1] ))
  286. $pendingApprovals = $invoiceManage [$key + 1] [0];
  287. break;
  288. }
  289. }
  290. if ($status != 4 && ! empty ( $pendingApprovals ))
  291. $invoice->pendingApprovals = $pendingApprovals;
  292. $invoice->processApprovals = json_encode ( $processApprovals );
  293. }
  294. $item = array (
  295. 'operation' => "同意"
  296. );
  297. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  298. $invoice->status = $status;
  299. $invoice->pendingApprovals = 0;
  300. } elseif ($status == 4) {
  301. $invoice->status = $status;
  302. $item = array (
  303. 'operation' => "终止"
  304. );
  305. }
  306. }
  307. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  308. $invoice->update ( array (
  309. 'where' => 'iid=' . $iid
  310. ) );
  311. $item += array (
  312. 'date' => date ( "Y-m-d H:i:s" ),
  313. 'img' => $this->staff [0] ['avatar'],
  314. 'username' => $this->staff [0] ['username'],
  315. 'uid' => $this->staff [0] ['sid'],
  316. 'category' => $this->staff [0] ['category'],
  317. 'status' => $status,
  318. 'iid' => $iid
  319. );
  320. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  321. return '/invoiceApproval';
  322. }
  323. die ( 'illegal request' );
  324. }
  325. /**
  326. * 展示需要打印的发票数据
  327. *
  328. * @since 1.0.0
  329. */
  330. function invoicePrint() {
  331. Doo::loadModel ( 'invoice' );
  332. $invoice = new invoice ();
  333. Doo::loadClass ( 'XDeode' );
  334. $XDeode = new XDeode ( 5 );
  335. Doo::loadModel ( 'staff' );
  336. $staff = new staff ();
  337. $toPrint = $invoice->find ( array (
  338. 'where' => 'status=2 ',
  339. 'desc' => 'iid',
  340. 'asArray' => true
  341. ) );
  342. $printed = $invoice->find ( array (
  343. 'where' => 'status=5 ',
  344. 'desc' => 'iid',
  345. 'asArray' => true
  346. ) );
  347. foreach ( $toPrint as $key => $value ) {
  348. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  349. $lastApprover = json_decode ( $value ['processApprovals'], true );
  350. if (! empty ( $lastApprover )) {
  351. $lastApproverKey = array_keys ( $lastApprover );
  352. $lastApprover = end ( $lastApprover );
  353. $staffDetail = $staff->getOne ( array (
  354. 'where' => 'sid=' . end ( $lastApproverKey ),
  355. 'asArray' => true
  356. ) );
  357. $lastApprover ['username'] = $staffDetail ['username'];
  358. }
  359. $toPrint [$key] ['lastApprover'] = $lastApprover;
  360. }
  361. foreach ( $printed as $key => $value ) {
  362. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  363. $lastApprover = json_decode ( $value ['processApprovals'], true );
  364. if (! empty ( $lastApprover )) {
  365. $lastApproverKey = array_keys ( $lastApprover );
  366. $lastApprover = end ( $lastApprover );
  367. $staffDetail = $staff->getOne ( array (
  368. 'where' => 'sid=' . end ( $lastApproverKey ),
  369. 'asArray' => true
  370. ) );
  371. $lastApprover ['username'] = $staffDetail ['username'];
  372. }
  373. $printed [$key] ['lastApprover'] = $lastApprover;
  374. }
  375. $data ['printed'] = $printed;
  376. $data ['toPrint'] = $toPrint;
  377. $data ['memu'] = "invoice";
  378. $data ['staff'] = $this->staff;
  379. $data ['receiptMemu'] = 'invoicePrint';
  380. $this->render ( "/admin/invoicePrint", $data );
  381. }
  382. /**
  383. * 展示发票打印的详情页面
  384. *
  385. * @since 1.0.0
  386. */
  387. function invoicePrintDetail() {
  388. Doo::loadClass ( 'XDeode' );
  389. $XDeode = new XDeode ( 5 );
  390. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  391. $iid = $XDeode->decode ( $iid );
  392. if (! is_numeric ( $iid ))
  393. die ( 'illegal request' );
  394. Doo::loadModel ( 'invoice' );
  395. $invoice = new invoice ();
  396. Doo::loadModel ( 'invoiceOperationLog' );
  397. $invoiceOperationLog = new invoiceOperationLog ();
  398. $invoiceDetail = $invoice->getOne ( array (
  399. 'where' => 'status=2 and iid=' . $iid,
  400. 'asArray' => true
  401. ) );
  402. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  403. $data ['invoiceDetail'] = $invoiceDetail;
  404. $data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  405. $data ['INVOICEKEY'] = $this->authcode ( $invoiceDetail ['iid'], '' );
  406. $data ['memu'] = "invoice";
  407. $data ['staff'] = $this->staff;
  408. $data ['receiptMemu'] = 'invoicePrint';
  409. $this->render ( "/admin/invoicePrintDetail", $data );
  410. }
  411. /**
  412. * 填写票号并完成打印
  413. * @since 1.0.0
  414. */
  415. function invoicePrintDo() {
  416. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  417. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  418. $iid = $this->authcode ( $iid );
  419. if (! is_numeric ( $iid ))
  420. die ( 'illegal request' );
  421. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  422. Doo::loadModel ( 'invoice' );
  423. $invoice = new invoice ();
  424. Doo::loadModel ( 'invoiceOperationLog' );
  425. $invoiceOperationLog = new invoiceOperationLog ();
  426. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  427. if (empty ( $invoicePrintDetail ))
  428. die ( 'illegal request' );
  429. $item = array (
  430. 'iid' => $iid,
  431. 'status' => 5,
  432. 'updateTime' => date ( "Y-m-d H:i:s" ),
  433. 'printTime' => date ( "Y-m-d H:i:s" ),
  434. 'invoiceNo' => $invoiceNo
  435. );
  436. $invoice->setPrintByInvoice ( $item );
  437. $item = array (
  438. 'date' => date ( "Y-m-d H:i:s" ),
  439. 'operation' => $invoiceNo,
  440. 'status' => 5,
  441. 'img' => $this->staff [0] ['avatar'],
  442. 'username' => $this->staff [0] ['username'],
  443. 'uid' => $this->staff [0] ['sid'],
  444. 'category' => $this->staff [0] ['category'],
  445. 'iid' => $iid
  446. );
  447. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  448. return "/invoicePrint";
  449. }
  450. }
  451. /**
  452. * 需要邮寄的发票
  453. * @since 1.0.0
  454. */
  455. function invoicePost() {
  456. Doo::loadModel ( 'invoice' );
  457. $invoice = new invoice ();
  458. $invoicePost = $invoice->getPostByInvoice ();
  459. $data ['invoicePost'] = $invoicePost;
  460. $data ['memu'] = "invoice";
  461. $data ['staff'] = $this->staff;
  462. $data ['receiptMemu'] = 'invoicePost';
  463. $this->render ( "/admin/invoicePost", $data );
  464. }
  465. private function getExeCount() {
  466. Doo::loadModel ( 'receipt' );
  467. $receipt = new receipt ();
  468. $receiptList = $receipt->find ( array (
  469. 'where' => '(executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff NOT LIKE \'%' . $this->staff [0] ['sid'] . '%\' ) and (status=1 or status=6)',
  470. 'desc' => 'rid',
  471. 'asArray' => true
  472. ) );
  473. return count ( $receiptList );
  474. }
  475. private function getReceiptCount() {
  476. $status = 2;
  477. $year = date ( 'Y' );
  478. Doo::loadModel ( 'receipt' );
  479. $receipt = new receipt ();
  480. Doo::loadModel ( 'verify' );
  481. $dateCondition = " and Year(date) =" . $year;
  482. $approvalCondition = ' and nowStaff like "%' . $this->staff [0] ['sid'] . '%" ';
  483. $receiptList = $receipt->find ( array (
  484. 'where' => ' status=' . $status . $dateCondition . $approvalCondition,
  485. 'desc' => 'rid',
  486. 'asArray' => true
  487. ) );
  488. return count ( $receiptList );
  489. }
  490. function _GetFileEXT($filename) {
  491. $pics = explode ( '.', $filename );
  492. $num = count ( $pics );
  493. return $pics [$num - 1];
  494. }
  495. /**
  496. * 获取get或者POST值
  497. *
  498. * @param string $name 属性名称
  499. * @return fixed 值
  500. */
  501. function get_args($name) {
  502. if (isset ( $_GET [$name] )) {
  503. if (is_array ( $_GET [$name] ))
  504. return $_GET [$name];
  505. else
  506. return addslashes ( $_GET [$name] );
  507. } elseif (isset ( $_POST [$name] )) {
  508. if (is_array ( $_POST [$name] ))
  509. return $_POST [$name];
  510. else
  511. return addslashes ( $_POST [$name] );
  512. } else
  513. return false;
  514. }
  515. /**
  516. * 加密或解密指定字符串
  517. *
  518. * @param string $string 要加密或解密的字符串
  519. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  520. * @param string $key 加解密的key
  521. * @param $expiry 超时值
  522. *
  523. */
  524. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  525. $ckey_length = 4;
  526. if (! $key) {
  527. $key = $this->INVOICEKEY;
  528. }
  529. $key = md5 ( $key );
  530. $keya = md5 ( substr ( $key, 0, 16 ) );
  531. $keyb = md5 ( substr ( $key, 16, 16 ) );
  532. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  533. $cryptkey = $keya . md5 ( $keya . $keyc );
  534. $key_length = strlen ( $cryptkey );
  535. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  536. $string_length = strlen ( $string );
  537. $result = '';
  538. $box = range ( 0, 255 );
  539. $rndkey = array ();
  540. for($i = 0; $i <= 255; $i ++) {
  541. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  542. }
  543. for($j = $i = 0; $i < 256; $i ++) {
  544. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  545. $tmp = $box [$i];
  546. $box [$i] = $box [$j];
  547. $box [$j] = $tmp;
  548. }
  549. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  550. $a = ($a + 1) % 256;
  551. $j = ($j + $box [$a]) % 256;
  552. $tmp = $box [$a];
  553. $box [$a] = $box [$j];
  554. $box [$j] = $tmp;
  555. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  556. }
  557. if ($operation == 'DECODE') {
  558. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  559. return substr ( $result, 26 );
  560. } else {
  561. return '';
  562. }
  563. } else {
  564. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  565. }
  566. }
  567. }
  568. ?>