invoiceReceivables.php 6.1 KB

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