invoiceReceivables.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. /**
  103. * 根据发票ID和绑定状态获得收款数据,绑定状态为ALL获取所有状态数据
  104. * @param string $iid 发票ID
  105. * @param string $bindStatus
  106. * @return mixed
  107. */
  108. public function getInvoiceReceivablesByIid($iid="",$bindStatus="All"){
  109. $iid=$this->authcode ($iid );
  110. $list=array();
  111. if (!empty($iid)&&is_numeric($iid)){
  112. $sql='';
  113. if ($bindStatus==1)
  114. $sql=" and bindStatus=1";
  115. elseif ($bindStatus==0)
  116. $sql=" and bindStatus=0";
  117. $list = $this->find ( array (
  118. 'where' => " iid=" . $iid.$sql,
  119. 'asArray' => TRUE
  120. ) );
  121. }
  122. foreach ( $list as $key => $value ) {
  123. $list [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  124. $staff = explode ( "-", $value ['receivablesStaff'] );
  125. $list [$key] ['sid'] = $staff [0];
  126. $list [$key] ['username'] = $staff [1];
  127. }
  128. return $list;
  129. }
  130. public function getInvoiceReceivablesInIridString($iridString=""){
  131. $list=array();
  132. if (!empty($iridString))
  133. $list = $this->find ( array (
  134. 'where' => " irid in(" . $iridString.")",
  135. 'asArray' => TRUE
  136. ) );
  137. return $list;
  138. }
  139. public function getInvoiceReceivablesByIrid($irid=""){
  140. $irid=$this->authcode ($irid );
  141. $detail=array();
  142. if (!empty($irid)&&is_numeric($irid))
  143. $detail = $this->getOne ( array (
  144. 'where' => " irid=" . $irid,
  145. 'asArray' => TRUE
  146. ) );
  147. return $detail;
  148. }
  149. /**
  150. * 添加一个收款
  151. * @param array $item 收款相关数据
  152. * @return number 返回收款ID
  153. */
  154. public function addInvoiceReceivables($item = array()) {
  155. $lid = 0;
  156. if (is_array ( $item ) && ! empty ( $item )) {
  157. foreach ( $item as $key => $value ) {
  158. $this->$key = $value;
  159. }
  160. $lid = $this->insert ();
  161. }
  162. return $lid;
  163. }
  164. /**
  165. * 根据参数字段更新相应字段(主键ID必须传)
  166. * @param array $item 相关需要更新的字段信息
  167. * @return number 返回发票ID
  168. */
  169. public function setInvoiceReceivablesByCondition($item = array()) {
  170. $lid = 0;
  171. if (is_array ( $item ) && ! empty ( $item )) {
  172. foreach ( $item as $key => $value ) {
  173. $this->$key = $value;
  174. }
  175. $lid = $this->update ();
  176. }
  177. return $lid;
  178. }
  179. /**
  180. * 加密或解密指定字符串
  181. *
  182. * @param string $string 要加密或解密的字符串
  183. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  184. * @param string $key 加解密的key
  185. * @param $expiry 超时值
  186. *
  187. */
  188. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  189. $ckey_length = 4;
  190. if (! $key) {
  191. $key = $this->INVOICEKEY;
  192. }
  193. $key = md5 ( $key );
  194. $keya = md5 ( substr ( $key, 0, 16 ) );
  195. $keyb = md5 ( substr ( $key, 16, 16 ) );
  196. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  197. $cryptkey = $keya . md5 ( $keya . $keyc );
  198. $key_length = strlen ( $cryptkey );
  199. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  200. $string_length = strlen ( $string );
  201. $result = '';
  202. $box = range ( 0, 255 );
  203. $rndkey = array ();
  204. for($i = 0; $i <= 255; $i ++) {
  205. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  206. }
  207. for($j = $i = 0; $i < 256; $i ++) {
  208. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  209. $tmp = $box [$i];
  210. $box [$i] = $box [$j];
  211. $box [$j] = $tmp;
  212. }
  213. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  214. $a = ($a + 1) % 256;
  215. $j = ($j + $box [$a]) % 256;
  216. $tmp = $box [$a];
  217. $box [$a] = $box [$j];
  218. $box [$j] = $tmp;
  219. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  220. }
  221. if ($operation == 'DECODE') {
  222. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  223. return substr ( $result, 26 );
  224. } else {
  225. return '';
  226. }
  227. } else {
  228. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  229. }
  230. }
  231. }
  232. ?>