InvoiceController.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  110. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  111. $moldManage = array ();
  112. foreach ( $invoiceManageList as $key => $value ) {
  113. if ($value ['mold'] == '发票打印')
  114. $moldManage [$value ['mold']] = $value ['staffList'];
  115. }
  116. $item = array (
  117. 'cid' => $cid,
  118. 'categoryName' => $categoryDetil ['title'],
  119. 'invoiceElement' => $invoiceElement,
  120. 'invoicePrice' => $invoicePrice,
  121. 'invoiceType' => $invoiceType,
  122. 'doPost' => $doPost,
  123. 'status' => 1,
  124. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  125. 'date' => date ( "Y-m-d H:i:s" ),
  126. 'updateTime' => date ( "Y-m-d H:i:s" ),
  127. 'sid' => $this->staff [0] ['sid'],
  128. 'userName' => $this->staff [0] ['username'],
  129. 'invoiceManage' => $invoiceManageDetail ['staff'],
  130. 'pendingApprovals' => $invoiceManageDetail ['staffList'] [0] [0],
  131. 'moldManage' => json_encode ( $moldManage ),
  132. 'remark' => $remark
  133. );
  134. if ($invoiceType == 0)
  135. $item += array (
  136. 'invoiceTitle' => $invoiceTitle
  137. );
  138. else {
  139. $item += array (
  140. 'invoiceCompany' => $invoiceCompany,
  141. 'TIN' => $TIN,
  142. 'address' => $address,
  143. 'phone' => $phone,
  144. 'bank' => $bank,
  145. 'bankAccount' => $bankAccount
  146. );
  147. }
  148. if ($doPost == 1) {
  149. $item += array (
  150. 'recipients' => $recipients,
  151. 'recipientsPhone' => $recipientsPhone,
  152. 'recipientsAddress' => $recipientsAddress,
  153. 'mailItems' => $mailItems
  154. );
  155. }
  156. $iid = $invoice->addInvoice ( $item );
  157. $item = array (
  158. 'date' => date ( "Y-m-d H:i:s" ),
  159. 'operation' => "创建",
  160. 'status' => 1,
  161. 'img' => $this->staff [0] ['avatar'],
  162. 'username' => $this->staff [0] ['username'],
  163. 'uid' => $this->staff [0] ['sid'],
  164. 'category' => $this->staff [0] ['category'],
  165. 'iid' => $iid
  166. );
  167. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  168. $item = array (
  169. 'date' => date ( "Y-m-d H:i:s" ),
  170. 'operation' => "提交审批",
  171. 'status' => 1,
  172. 'img' => $this->staff [0] ['avatar'],
  173. 'username' => $this->staff [0] ['username'],
  174. 'uid' => $this->staff [0] ['sid'],
  175. 'category' => $this->staff [0] ['category'],
  176. 'iid' => $iid
  177. );
  178. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  179. }
  180. return "/invoice";
  181. }
  182. function invoiceApproval() {
  183. Doo::loadModel ( 'invoice' );
  184. $invoice = new invoice ();
  185. Doo::loadClass ( 'XDeode' );
  186. $XDeode = new XDeode ( 5 );
  187. Doo::loadModel ( 'staff' );
  188. $staff = new staff ();
  189. $invoiceList = $invoice->find ( array (
  190. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  191. 'desc' => 'iid',
  192. 'asArray' => true
  193. ) );
  194. foreach ( $invoiceList as $key => $value ) {
  195. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  196. $lastApprover = json_decode ( $value ['processApprovals'], true );
  197. if (! empty ( $lastApprover )) {
  198. $lastApproverKey = array_keys ( $lastApprover );
  199. $lastApprover = end ( $lastApprover );
  200. $staffDetail = $staff->getOne ( array (
  201. 'where' => 'sid=' . end ( $lastApproverKey ),
  202. 'asArray' => true
  203. ) );
  204. $lastApprover ['username'] = $staffDetail ['username'];
  205. }
  206. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  207. }
  208. $data ['invoiceList'] = $invoiceList;
  209. $data ['memu'] = "invoice";
  210. $data ['staff'] = $this->staff;
  211. $data ['receiptMemu'] = 'invoiceApproval';
  212. $this->render ( "/admin/invoiceApproval", $data );
  213. }
  214. function invoiceDetail() {
  215. Doo::loadClass ( 'XDeode' );
  216. $XDeode = new XDeode ( 5 );
  217. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  218. $iid = $XDeode->decode ( $iid );
  219. if (! is_numeric ( $iid ))
  220. die ( 'illegal request' );
  221. Doo::loadModel ( 'invoice' );
  222. $invoice = new invoice ();
  223. Doo::loadModel ( 'invoiceOperationLog' );
  224. $invoiceOperationLog = new invoiceOperationLog ();
  225. $invoiceDetail = $invoice->getOne ( array (
  226. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  227. 'asArray' => true
  228. ) );
  229. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  230. $data ['invoiceDetail'] = $invoiceDetail;
  231. $data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  232. $data ['INVOICEKEY'] = $this->authcode ( $invoiceDetail ['iid'], '' );
  233. $data ['memu'] = "invoice";
  234. $data ['staff'] = $this->staff;
  235. $data ['receiptMemu'] = 'invoiceApproval';
  236. $this->render ( "/admin/invoiceApprovalDetail", $data );
  237. }
  238. /**
  239. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  240. *
  241. * @since 1.0.0
  242. * @var integer iid 开票ID 已加密
  243. * @var integer status 发票审批状态
  244. * @var integer opintion 审批发票的意见
  245. * @return string 如操作成功返回审批首页
  246. */
  247. function invoiceApprovalDo() {
  248. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  249. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  250. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  251. $iid = $this->authcode ( $iid );
  252. if (! is_numeric ( $iid ))
  253. die ( 'illegal request' );
  254. if (! empty ( $iid ) && ! empty ( $status ) && ! empty ( $opinion )) {
  255. if (! ($status == 2 || $status == 3 || $status == 4))
  256. die ( 'illegal request' );
  257. Doo::loadModel ( 'invoice' );
  258. $invoice = new invoice ();
  259. Doo::loadModel ( 'invoiceOperationLog' );
  260. $invoiceOperationLog = new invoiceOperationLog ();
  261. $invoiceDetail = $invoice->getOne ( array (
  262. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  263. 'asArray' => true
  264. ) );
  265. if (empty ( $invoiceDetail ))
  266. die ( 'illegal request' );
  267. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  268. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  269. if ($status == 3) {
  270. $invoice->status = $status;
  271. $item = array (
  272. 'operation' => "退回"
  273. );
  274. } else {
  275. if (empty ( $processApprovals )) {
  276. $processApprovals = array (
  277. $this->staff [0] ['sid'] => array (
  278. 'date' => date ( "Y-m-d H:i:s" ),
  279. 'opinion' => $opinion,
  280. 'status' => $status
  281. )
  282. );
  283. if ($status != 4 && isset ( $invoiceManage [1] ))
  284. $invoice->pendingApprovals = $invoiceManage [1] [0];
  285. $invoice->processApprovals = json_encode ( $processApprovals );
  286. } else {
  287. $processApprovals [$this->staff [0] ['sid']] = array (
  288. 'date' => date ( "Y-m-d H:i:s" ),
  289. 'opinion' => $opinion,
  290. 'status' => $status
  291. );
  292. $pendingApprovals = 0;
  293. foreach ( $invoiceManage as $key => $value ) {
  294. if ($value [0] == $this->staff [0] ['sid']) {
  295. if (isset ( $invoiceManage [$key + 1] ))
  296. $pendingApprovals = $invoiceManage [$key + 1] [0];
  297. break;
  298. }
  299. }
  300. if ($status != 4 && ! empty ( $pendingApprovals ))
  301. $invoice->pendingApprovals = $pendingApprovals;
  302. $invoice->processApprovals = json_encode ( $processApprovals );
  303. }
  304. $item = array (
  305. 'operation' => "同意"
  306. );
  307. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  308. $invoice->status = $status;
  309. $invoice->pendingApprovals = 0;
  310. } elseif ($status == 4) {
  311. $invoice->status = $status;
  312. $item = array (
  313. 'operation' => "终止"
  314. );
  315. }
  316. }
  317. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  318. $invoice->update ( array (
  319. 'where' => 'iid=' . $iid
  320. ) );
  321. $item += array (
  322. 'date' => date ( "Y-m-d H:i:s" ),
  323. 'img' => $this->staff [0] ['avatar'],
  324. 'username' => $this->staff [0] ['username'],
  325. 'uid' => $this->staff [0] ['sid'],
  326. 'category' => $this->staff [0] ['category'],
  327. 'status' => $status,
  328. 'iid' => $iid
  329. );
  330. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  331. return '/invoiceApproval';
  332. }
  333. die ( 'illegal request' );
  334. }
  335. /**
  336. * 展示需要打印的发票数据
  337. *
  338. * @since 1.0.0
  339. */
  340. function invoicePrint() {
  341. Doo::loadModel ( 'invoice' );
  342. $invoice = new invoice ();
  343. Doo::loadClass ( 'XDeode' );
  344. $XDeode = new XDeode ( 5 );
  345. Doo::loadModel ( 'staff' );
  346. $staff = new staff ();
  347. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 2 );
  348. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 5 );
  349. foreach ( $toPrint as $key => $value ) {
  350. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  351. $lastApprover = json_decode ( $value ['processApprovals'], true );
  352. if (! empty ( $lastApprover )) {
  353. $lastApproverKey = array_keys ( $lastApprover );
  354. $lastApprover = end ( $lastApprover );
  355. $staffDetail = $staff->getOne ( array (
  356. 'where' => 'sid=' . end ( $lastApproverKey ),
  357. 'asArray' => true
  358. ) );
  359. $lastApprover ['username'] = $staffDetail ['username'];
  360. }
  361. $toPrint [$key] ['lastApprover'] = $lastApprover;
  362. }
  363. foreach ( $printed as $key => $value ) {
  364. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  365. $lastApprover = json_decode ( $value ['processApprovals'], true );
  366. if (! empty ( $lastApprover )) {
  367. $lastApproverKey = array_keys ( $lastApprover );
  368. $lastApprover = end ( $lastApprover );
  369. $staffDetail = $staff->getOne ( array (
  370. 'where' => 'sid=' . end ( $lastApproverKey ),
  371. 'asArray' => true
  372. ) );
  373. $lastApprover ['username'] = $staffDetail ['username'];
  374. }
  375. $printed [$key] ['lastApprover'] = $lastApprover;
  376. }
  377. $data ['printed'] = $printed;
  378. $data ['toPrint'] = $toPrint;
  379. $data ['memu'] = "invoice";
  380. $data ['staff'] = $this->staff;
  381. $data ['receiptMemu'] = 'invoicePrint';
  382. $this->render ( "/admin/invoicePrint", $data );
  383. }
  384. /**
  385. * 展示发票打印的详情页面
  386. *
  387. * @since 1.0.0
  388. */
  389. function invoicePrintDetail() {
  390. Doo::loadClass ( 'XDeode' );
  391. $XDeode = new XDeode ( 5 );
  392. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  393. $iid = $XDeode->decode ( $iid );
  394. if (! is_numeric ( $iid ))
  395. die ( 'illegal request' );
  396. Doo::loadModel ( 'invoice' );
  397. $invoice = new invoice ();
  398. Doo::loadModel ( 'invoiceOperationLog' );
  399. $invoiceOperationLog = new invoiceOperationLog ();
  400. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 2, $iid );
  401. if (empty ( $invoiceDetail ))
  402. die ( 'illegal request' );
  403. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  404. $data ['invoiceDetail'] = $invoiceDetail;
  405. $data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  406. $data ['INVOICEKEY'] = $this->authcode ( $invoiceDetail ['iid'], '' );
  407. $data ['memu'] = "invoice";
  408. $data ['staff'] = $this->staff;
  409. $data ['receiptMemu'] = 'invoicePrint';
  410. $this->render ( "/admin/invoicePrintDetail", $data );
  411. }
  412. /**
  413. * 填写票号并完成打印
  414. * @since 1.0.0
  415. */
  416. function invoicePrintDo() {
  417. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  418. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  419. $iid = $this->authcode ( $iid );
  420. if (! is_numeric ( $iid ))
  421. die ( 'illegal request' );
  422. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  423. Doo::loadModel ( 'invoice' );
  424. $invoice = new invoice ();
  425. Doo::loadModel ( 'invoiceOperationLog' );
  426. $invoiceOperationLog = new invoiceOperationLog ();
  427. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  428. if (empty ( $invoicePrintDetail ))
  429. die ( 'illegal request' );
  430. $item = array (
  431. 'iid' => $iid,
  432. 'status' => 5,
  433. 'updateTime' => date ( "Y-m-d H:i:s" ),
  434. 'printTime' => date ( "Y-m-d H:i:s" ),
  435. 'invoiceNo' => $invoiceNo
  436. );
  437. $invoice->setPrintByInvoice ( $item );
  438. $item = array (
  439. 'date' => date ( "Y-m-d H:i:s" ),
  440. 'operation' => $invoiceNo,
  441. 'status' => 5,
  442. 'img' => $this->staff [0] ['avatar'],
  443. 'username' => $this->staff [0] ['username'],
  444. 'uid' => $this->staff [0] ['sid'],
  445. 'category' => $this->staff [0] ['category'],
  446. 'iid' => $iid
  447. );
  448. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  449. return "/invoicePrint";
  450. }
  451. }
  452. /**
  453. * 需要邮寄的发票
  454. * @since 1.0.0
  455. */
  456. function invoicePost() {
  457. Doo::loadModel ( 'invoice' );
  458. $invoice = new invoice ();
  459. $invoicePost = $invoice->getPostByInvoice ();
  460. $data ['invoicePost'] = $invoicePost;
  461. $data ['memu'] = "invoice";
  462. $data ['staff'] = $this->staff;
  463. $data ['receiptMemu'] = 'invoicePost';
  464. $this->render ( "/admin/invoicePost", $data );
  465. }
  466. private function getExeCount() {
  467. Doo::loadModel ( 'receipt' );
  468. $receipt = new receipt ();
  469. $receiptList = $receipt->find ( array (
  470. 'where' => '(executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff NOT LIKE \'%' . $this->staff [0] ['sid'] . '%\' ) and (status=1 or status=6)',
  471. 'desc' => 'rid',
  472. 'asArray' => true
  473. ) );
  474. return count ( $receiptList );
  475. }
  476. private function getReceiptCount() {
  477. $status = 2;
  478. $year = date ( 'Y' );
  479. Doo::loadModel ( 'receipt' );
  480. $receipt = new receipt ();
  481. Doo::loadModel ( 'verify' );
  482. $dateCondition = " and Year(date) =" . $year;
  483. $approvalCondition = ' and nowStaff like "%' . $this->staff [0] ['sid'] . '%" ';
  484. $receiptList = $receipt->find ( array (
  485. 'where' => ' status=' . $status . $dateCondition . $approvalCondition,
  486. 'desc' => 'rid',
  487. 'asArray' => true
  488. ) );
  489. return count ( $receiptList );
  490. }
  491. function _GetFileEXT($filename) {
  492. $pics = explode ( '.', $filename );
  493. $num = count ( $pics );
  494. return $pics [$num - 1];
  495. }
  496. /**
  497. * 获取get或者POST值
  498. *
  499. * @param string $name 属性名称
  500. * @return fixed 值
  501. */
  502. function get_args($name) {
  503. if (isset ( $_GET [$name] )) {
  504. if (is_array ( $_GET [$name] ))
  505. return $_GET [$name];
  506. else
  507. return addslashes ( $_GET [$name] );
  508. } elseif (isset ( $_POST [$name] )) {
  509. if (is_array ( $_POST [$name] ))
  510. return $_POST [$name];
  511. else
  512. return addslashes ( $_POST [$name] );
  513. } else
  514. return false;
  515. }
  516. /**
  517. * 加密或解密指定字符串
  518. *
  519. * @param string $string 要加密或解密的字符串
  520. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  521. * @param string $key 加解密的key
  522. * @param $expiry 超时值
  523. *
  524. */
  525. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  526. $ckey_length = 4;
  527. if (! $key) {
  528. $key = $this->INVOICEKEY;
  529. }
  530. $key = md5 ( $key );
  531. $keya = md5 ( substr ( $key, 0, 16 ) );
  532. $keyb = md5 ( substr ( $key, 16, 16 ) );
  533. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  534. $cryptkey = $keya . md5 ( $keya . $keyc );
  535. $key_length = strlen ( $cryptkey );
  536. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  537. $string_length = strlen ( $string );
  538. $result = '';
  539. $box = range ( 0, 255 );
  540. $rndkey = array ();
  541. for($i = 0; $i <= 255; $i ++) {
  542. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  543. }
  544. for($j = $i = 0; $i < 256; $i ++) {
  545. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  546. $tmp = $box [$i];
  547. $box [$i] = $box [$j];
  548. $box [$j] = $tmp;
  549. }
  550. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  551. $a = ($a + 1) % 256;
  552. $j = ($j + $box [$a]) % 256;
  553. $tmp = $box [$a];
  554. $box [$a] = $box [$j];
  555. $box [$j] = $tmp;
  556. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  557. }
  558. if ($operation == 'DECODE') {
  559. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  560. return substr ( $result, 26 );
  561. } else {
  562. return '';
  563. }
  564. } else {
  565. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  566. }
  567. }
  568. }
  569. ?>