invoiceReceivables.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. /**
  47. * 获取最新几条收款包括最新的一条操作日志
  48. * @param number $limit
  49. * @return unknown
  50. */
  51. public function getInvoiceReceivablesByNew($limit = 4) {
  52. $list = $this->find ( array (
  53. 'desc' => 'irid',
  54. 'limit'=>$limit,
  55. 'asArray' => TRUE
  56. ) );
  57. Doo::loadModel ( 'invoiceROLog' );
  58. $invoiceROLog = new invoiceROLog ();
  59. foreach ($list as $key=>$value){
  60. $list[$key]['invoiceROLog']=$invoiceROLog->getInvoiceROLogByIrid($value['irid'],'desc');
  61. }
  62. return $list;
  63. }
  64. public function getInvoiceReceivablesByClaim($cid = 0, $sid = 0) {
  65. if (empty ( $sid )) {
  66. $list ['csClaim'] = $this->find ( array (
  67. 'where' => "receivablesCategory='public' and receivablesStaff='public' and bindStatus=0",
  68. 'desc' => 'irid',
  69. 'asArray' => TRUE
  70. ) );
  71. foreach ( $list ['csClaim'] as $key => $value ) {
  72. $list ['csClaim'] [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  73. // $list ['csClaim'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  74. }
  75. $list ['sClaim'] = $this->find ( array (
  76. 'where' => "receivablesCategory!='public' and receivablesStaff='public' and receivablesCategory like '" . $cid . ":%' and bindStatus=0",
  77. 'desc' => 'irid',
  78. 'asArray' => TRUE
  79. ) );
  80. foreach ( $list ['sClaim'] as $key => $value ) {
  81. $list ['sClaim'] [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  82. }
  83. $list ['arClaim'] = $this->find ( array (
  84. 'where' => "receivablesCategory!='public' and receivablesStaff!='public' and receivablesCategory like '" . $cid . ":%' and receivablesStaff like '".$sid."-%' and bindStatus=0",
  85. 'desc' => 'irid',
  86. 'asArray' => TRUE
  87. ) );
  88. foreach ( $list ['arClaim'] as $key => $value ) {
  89. $staff = explode ( "-", $value ['receivablesStaff'] );
  90. $list ['arClaim'] [$key] ['sid'] = $staff [0];
  91. $list ['arClaim'] [$key] ['username'] = $staff [1];
  92. }
  93. }
  94. if (! empty ( $cid ) && ! empty ( $sid )) {
  95. $list ['myClaim'] = $this->find ( array (
  96. 'where' => " receivablesStaff like '" . $sid . "-%' and receivablesCategory like '" . $cid . ":%' and bindStatus=0",
  97. 'desc' => 'irid',
  98. 'asArray' => TRUE
  99. ) );
  100. foreach ( $list ['myClaim'] as $key => $value ) {
  101. $list ['myClaim'] [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  102. $staff = explode ( "-", $value ['receivablesStaff'] );
  103. $list ['myClaim'] [$key] ['sid'] = $staff [0];
  104. $list ['myClaim'] [$key] ['username'] = $staff [1];
  105. }
  106. $list ['bindClaim'] = $this->find ( array (
  107. 'where' => " bindStatus=1 and receivablesStaff like '".$sid."-%' ",
  108. 'desc' => 'irid',
  109. 'limit' => 3,
  110. 'asArray' => TRUE
  111. ) );
  112. Doo::loadModel ( 'invoice' );
  113. $invoice = new invoice ();
  114. Doo::loadClass ( 'XDeode' );
  115. $XDeode = new XDeode ( 5 );
  116. foreach ( $list ['bindClaim'] as $key => $value ) {
  117. $id=$invoice->getInvoiceByIid ( $value ['iid'] );
  118. $id['iidKeyUrl']= $XDeode->encode ( $id ['iid'] );
  119. $list ['bindClaim'] [$key] ['invoice'] = $id;
  120. $list ['bindClaim'] [$key] ['iridKeyUrl'] = $XDeode->encode ( $value ['irid'] );
  121. }
  122. }
  123. return $list;
  124. }
  125. /**
  126. * 根据发票ID和绑定状态获得收款数据,绑定状态为ALL获取所有状态数据
  127. * @param string $iid 发票ID
  128. * @param string $bindStatus
  129. * @return mixed
  130. */
  131. public function getInvoiceReceivablesByIid($iid = "", $bindStatus = "All") {
  132. Doo::loadClass ( 'XDeode' );
  133. $XDeode = new XDeode ( 5 );
  134. $iid = $this->authcode ( $iid );
  135. $list = array ();
  136. if (! empty ( $iid ) && is_numeric ( $iid )) {
  137. $sql = '';
  138. if ($bindStatus == 1)
  139. $sql = " and bindStatus=1";
  140. elseif ($bindStatus == 0)
  141. $sql = " and bindStatus=0";
  142. $list = $this->find ( array (
  143. 'where' => " iid=" . $iid . $sql,
  144. 'asArray' => TRUE
  145. ) );
  146. }
  147. foreach ( $list as $key => $value ) {
  148. $list [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  149. $staff = explode ( "-", $value ['receivablesStaff'] );
  150. $list [$key] ['sid'] = $staff [0];
  151. $list [$key] ['username'] = $staff [1];
  152. $list [$key] ['iridKey'] = $XDeode->encode ( $value ['irid'] );
  153. }
  154. return $list;
  155. }
  156. public function getInvoiceReceivablesInIridString($iridString = "") {
  157. $list = array ();
  158. if (! empty ( $iridString ))
  159. $list = $this->find ( array (
  160. 'where' => " irid in ( " . $iridString . " )",
  161. 'asArray' => TRUE
  162. ) );
  163. return $list;
  164. }
  165. public function getInvoiceReceivablesByIrid($irid = "") {
  166. Doo::loadClass ( 'XDeode' );
  167. $XDeode = new XDeode ( 5 );
  168. $irid = $this->authcode ( $irid );
  169. $detail = array ();
  170. if (! empty ( $irid ) && is_numeric ( $irid ))
  171. $detail = $this->getOne ( array (
  172. 'where' => " irid=" . $irid,
  173. 'asArray' => TRUE
  174. ) );
  175. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  176. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  177. return $detail;
  178. }
  179. public function getInvoiceReceivablesByIrsid($irid = "",$sid="") {
  180. Doo::loadClass ( 'XDeode' );
  181. $XDeode = new XDeode ( 5 );
  182. $irid = $XDeode->decode( $irid );
  183. $detail = array ();
  184. if (! empty ( $irid ) && is_numeric ( $irid )){
  185. $detail = $this->getOne ( array (
  186. 'where' => " irid=" . $irid." and receivablesStaff like '".$sid."_%'",
  187. 'asArray' => TRUE
  188. ) );
  189. $detail ['sid'] = '';
  190. $detail ['username'] = '';
  191. if (!empty($detail ['receivablesStaff'])){
  192. $staff = explode ( "-", $detail ['receivablesStaff'] );
  193. $detail ['sid'] = $staff [0];
  194. $detail ['username'] = $staff [1];
  195. }
  196. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  197. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  198. }
  199. return $detail;
  200. }
  201. /**
  202. * 添加一个收款
  203. * @param array $item 收款相关数据
  204. * @return number 返回收款ID
  205. */
  206. public function addInvoiceReceivables($item = array()) {
  207. $lid = 0;
  208. if (is_array ( $item ) && ! empty ( $item )) {
  209. foreach ( $item as $key => $value ) {
  210. $this->$key = $value;
  211. }
  212. $lid = $this->insert ();
  213. }
  214. return $lid;
  215. }
  216. /**
  217. * 根据参数字段更新相应字段(主键ID必须传)
  218. * @param array $item 相关需要更新的字段信息
  219. * @return number 返回发票ID
  220. */
  221. public function setInvoiceReceivablesByCondition($item = array()) {
  222. $lid = 0;
  223. if (is_array ( $item ) && ! empty ( $item )) {
  224. foreach ( $item as $key => $value ) {
  225. $this->$key = $value;
  226. }
  227. $lid = $this->update ();
  228. }
  229. return $lid;
  230. }
  231. /**
  232. * 加密或解密指定字符串
  233. *
  234. * @param string $string 要加密或解密的字符串
  235. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  236. * @param string $key 加解密的key
  237. * @param $expiry 超时值
  238. *
  239. */
  240. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  241. $ckey_length = 4;
  242. if (! $key) {
  243. $key = $this->INVOICEKEY;
  244. }
  245. $key = md5 ( $key );
  246. $keya = md5 ( substr ( $key, 0, 16 ) );
  247. $keyb = md5 ( substr ( $key, 16, 16 ) );
  248. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  249. $cryptkey = $keya . md5 ( $keya . $keyc );
  250. $key_length = strlen ( $cryptkey );
  251. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  252. $string_length = strlen ( $string );
  253. $result = '';
  254. $box = range ( 0, 255 );
  255. $rndkey = array ();
  256. for($i = 0; $i <= 255; $i ++) {
  257. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  258. }
  259. for($j = $i = 0; $i < 256; $i ++) {
  260. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  261. $tmp = $box [$i];
  262. $box [$i] = $box [$j];
  263. $box [$j] = $tmp;
  264. }
  265. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  266. $a = ($a + 1) % 256;
  267. $j = ($j + $box [$a]) % 256;
  268. $tmp = $box [$a];
  269. $box [$a] = $box [$j];
  270. $box [$j] = $tmp;
  271. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  272. }
  273. if ($operation == 'DECODE') {
  274. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  275. return substr ( $result, 26 );
  276. } else {
  277. return '';
  278. }
  279. } else {
  280. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  281. }
  282. }
  283. }
  284. ?>