invoicePaper.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. Doo::loadCore ( 'db/DooModel' );
  3. /**
  4. * 纸质发票相关信息及其操作业务逻辑
  5. * @author CP.
  6. * @version 1.0
  7. * @namespace invoice
  8. * @package invoiceModel
  9. */
  10. class invoicePaper extends DooModel {
  11. /**
  12. *
  13. * @var integer $iid 发票ID
  14. */
  15. public $ipid;
  16. public $invoiceType;
  17. public $invoiceCode;
  18. public $invoiceNo;
  19. public $iid;
  20. public $date;
  21. public $_table = 'CLD_invoicePaper';
  22. public $_primarykey = 'ipid';
  23. public $_fields = array (
  24. 'ipid',
  25. 'invoiceType',
  26. 'invoiceCode',
  27. 'invoiceNo',
  28. 'iid',
  29. 'date'
  30. );
  31. function getInvoicePaper($limit = 0, $con = "", $desc = 'desc') {
  32. if (empty ( $limit ) || empty ( $con ))
  33. return array ();
  34. $field = 'a.invoiceType,a.invoiceCode,a.invoiceNo,a.iid,a.date as paperDate,a.ipid
  35. ,b.invoiceSerial,b.invoiceTitle,b.invoiceCompany,b.invoicePrice,b.invoiceElement,b.date as invoiceDate,b.userName,b.categoryName,b.printTime';
  36. $sql = "select " . $field . " from " . $this->_table . " as a left join CLD_invoice as b on (a.iid=b.iid) " . $con . " ORDER BY a.invoiceNo " . $desc . ' limit ' . $limit;
  37. $query = Doo::db ()->query ( $sql );
  38. $list = $query->fetchAll ();
  39. Doo::loadClass ( 'XDeode' );
  40. $XDeode = new XDeode ( 5 );
  41. foreach ( $list as $key => $value ) {
  42. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  43. $list [$key] ['ipidKey'] = $XDeode->encode ( $value ['ipid'] );
  44. }
  45. return $list;
  46. }
  47. function getInvoicePaperCount() {
  48. $listCount = $this->count ( array (
  49. 'asArray' => TRUE
  50. ) );
  51. return $listCount;
  52. }
  53. /**
  54. * 根据发票类型获得未打印的发票号
  55. * @param number $invoiceType
  56. * @return unknown
  57. */
  58. function getInvoicePaperByInvoiceType( $invoiceType = 0) {
  59. $list = $this->find ( array (
  60. 'where' => 'iid=0 and invoiceType='.$invoiceType,
  61. 'asArray' => TRUE
  62. ) );
  63. Doo::loadClass ( 'XDeode' );
  64. $XDeode = new XDeode ( 5 );
  65. foreach ( $list as $key => $value ) {
  66. $list [$key] ['ipidKey'] = $XDeode->encode ( $value ['ipid'] );
  67. }
  68. return $list;
  69. }
  70. /**
  71. * 根据ID获得纸票号
  72. * @param number $ipid
  73. */
  74. function getInvoicePaperByIpid($ipid=0){
  75. $detail = $this->getOne ( array (
  76. 'where' => 'iid=0 and ipid='.$ipid,
  77. 'asArray' => TRUE
  78. ) );
  79. Doo::loadClass ( 'XDeode' );
  80. $XDeode = new XDeode ( 5 );
  81. if (empty ( $detail ) )
  82. return array ();
  83. $detail ['ipidKey'] = $XDeode->encode ( $detail ['ipid'] );
  84. return $detail;
  85. }
  86. /**
  87. * 根据参数字段更新相应字段(主键ID必须传)
  88. * @param array $item 相关需要更新的字段信息
  89. * @return number 返回发票ID
  90. */
  91. public function setInvoicePaperByCondition($item = array()) {
  92. $lid = 0;
  93. if (is_array ( $item ) && ! empty ( $item )) {
  94. foreach ( $item as $key => $value ) {
  95. $this->$key = $value;
  96. }
  97. $lid = $this->update ();
  98. }
  99. return $lid;
  100. }
  101. /**
  102. * 加密或解密指定字符串
  103. *
  104. * @param string $string 要加密或解密的字符串
  105. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  106. * @param string $key 加解密的key
  107. * @param $expiry 超时值
  108. *
  109. */
  110. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  111. $ckey_length = 4;
  112. if (! $key) {
  113. $key = $this->INVOICEKEY;
  114. }
  115. $key = md5 ( $key );
  116. $keya = md5 ( substr ( $key, 0, 16 ) );
  117. $keyb = md5 ( substr ( $key, 16, 16 ) );
  118. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  119. $cryptkey = $keya . md5 ( $keya . $keyc );
  120. $key_length = strlen ( $cryptkey );
  121. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  122. $string_length = strlen ( $string );
  123. $result = '';
  124. $box = range ( 0, 255 );
  125. $rndkey = array ();
  126. for($i = 0; $i <= 255; $i ++) {
  127. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  128. }
  129. for($j = $i = 0; $i < 256; $i ++) {
  130. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  131. $tmp = $box [$i];
  132. $box [$i] = $box [$j];
  133. $box [$j] = $tmp;
  134. }
  135. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  136. $a = ($a + 1) % 256;
  137. $j = ($j + $box [$a]) % 256;
  138. $tmp = $box [$a];
  139. $box [$a] = $box [$j];
  140. $box [$j] = $tmp;
  141. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  142. }
  143. if ($operation == 'DECODE') {
  144. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  145. return substr ( $result, 26 );
  146. } else {
  147. return '';
  148. }
  149. } else {
  150. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  151. }
  152. }
  153. }
  154. ?>