invoiceReceivables.php 5.6 KB

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