invoiceReceivables.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 invoiceReceivables extends DooModel {
  11. private $INVOICEKEY = "APPROVAL";
  12. public $irid;
  13. public $receivablesPrice;
  14. public $receivablesSerial;
  15. public $receivablesMessage;
  16. public $receivablesBank;
  17. public $receivablesDate;
  18. public $receivablesCategory;
  19. public $receivablesStaff;
  20. public $inputStaff;
  21. public $date;
  22. public $confirmTime;
  23. public $_table = 'CLD_invoiceReceivables';
  24. public $_primarykey = 'irid';
  25. public $_fields = array (
  26. 'irid',
  27. 'receivablesPrice',
  28. 'receivablesSerial',
  29. 'receivablesMessage',
  30. 'receivablesBank',
  31. 'receivablesDate',
  32. 'receivablesCategory',
  33. 'receivablesStaff',
  34. 'inputStaff',
  35. 'date',
  36. 'confirmTime'
  37. );
  38. public function getInvoiceReceivablesByClaim($cid){
  39. $list['csClaim'] = $this->find ( array (
  40. 'where' => "receivablesCategory='public' and receivablesStaff='public' ",
  41. 'desc' => 'irid',
  42. 'asArray' => TRUE
  43. ) );
  44. foreach ( $list ['csClaim'] as $key => $value ) {
  45. $list ['csClaim'] [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  46. //$list ['csClaim'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  47. }
  48. $list['sClaim'] = $this->find ( array (
  49. 'where' => "receivablesCategory!='public' and receivablesStaff='public' and receivablesCategory like '".$cid.":%'",
  50. 'desc' => 'irid',
  51. 'asArray' => TRUE
  52. ) );
  53. foreach ( $list ['sClaim'] as $key => $value ) {
  54. $list ['sClaim'] [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  55. }
  56. $list['arClaim'] = $this->find ( array (
  57. 'where' => "receivablesCategory!='public' and receivablesStaff!='public' and receivablesCategory like '".$cid.":%'",
  58. 'desc' => 'irid',
  59. 'asArray' => TRUE
  60. ) );
  61. foreach ( $list ['arClaim'] as $key => $value ) {
  62. $staff = explode ( "-", $value ['receivablesStaff'] );
  63. $list ['arClaim'] [$key] ['sid'] = $staff [0];
  64. $list ['arClaim'] [$key] ['username'] = $staff [1];
  65. }
  66. return $list;
  67. }
  68. public function getInvoiceReceivablesByIrid($irid=""){
  69. $irid=$this->authcode ($irid );
  70. $detail=array();
  71. if (!empty($irid)&&is_numeric($irid))
  72. $detail = $this->getOne ( array (
  73. 'where' => " irid=" . $irid,
  74. 'asArray' => TRUE
  75. ) );
  76. return $detail;
  77. }
  78. /**
  79. * 添加一个收款
  80. * @param array $item 收款相关数据
  81. * @return number 返回收款ID
  82. */
  83. public function addInvoiceReceivables($item = array()) {
  84. $lid = 0;
  85. if (is_array ( $item ) && ! empty ( $item )) {
  86. foreach ( $item as $key => $value ) {
  87. $this->$key = $value;
  88. }
  89. $lid = $this->insert ();
  90. }
  91. return $lid;
  92. }
  93. /**
  94. * 根据参数字段更新相应字段(主键ID必须传)
  95. * @param array $item 相关需要更新的字段信息
  96. * @return number 返回发票ID
  97. */
  98. public function setInvoiceReceivablesByCondition($item = array()) {
  99. $lid = 0;
  100. if (is_array ( $item ) && ! empty ( $item )) {
  101. foreach ( $item as $key => $value ) {
  102. $this->$key = $value;
  103. }
  104. $lid = $this->update ();
  105. }
  106. return $lid;
  107. }
  108. /**
  109. * 加密或解密指定字符串
  110. *
  111. * @param string $string 要加密或解密的字符串
  112. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  113. * @param string $key 加解密的key
  114. * @param $expiry 超时值
  115. *
  116. */
  117. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  118. $ckey_length = 4;
  119. if (! $key) {
  120. $key = $this->INVOICEKEY;
  121. }
  122. $key = md5 ( $key );
  123. $keya = md5 ( substr ( $key, 0, 16 ) );
  124. $keyb = md5 ( substr ( $key, 16, 16 ) );
  125. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  126. $cryptkey = $keya . md5 ( $keya . $keyc );
  127. $key_length = strlen ( $cryptkey );
  128. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  129. $string_length = strlen ( $string );
  130. $result = '';
  131. $box = range ( 0, 255 );
  132. $rndkey = array ();
  133. for($i = 0; $i <= 255; $i ++) {
  134. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  135. }
  136. for($j = $i = 0; $i < 256; $i ++) {
  137. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  138. $tmp = $box [$i];
  139. $box [$i] = $box [$j];
  140. $box [$j] = $tmp;
  141. }
  142. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  143. $a = ($a + 1) % 256;
  144. $j = ($j + $box [$a]) % 256;
  145. $tmp = $box [$a];
  146. $box [$a] = $box [$j];
  147. $box [$j] = $tmp;
  148. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  149. }
  150. if ($operation == 'DECODE') {
  151. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  152. return substr ( $result, 26 );
  153. } else {
  154. return '';
  155. }
  156. } else {
  157. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  158. }
  159. }
  160. }
  161. ?>