invoiceReceivables.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. $price=0;
  164. $serial=0;
  165. Doo::loadClass ( 'XDeode' );
  166. $XDeode = new XDeode ( 5 );
  167. foreach ($list as $key=>$value){
  168. $price+=$value['receivablesPrice'];
  169. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  170. }
  171. if (!empty($list))
  172. $list[0]['sumPrice']=$price;
  173. return $list;
  174. }
  175. /**
  176. * 根据收款ID获取一条相关数据
  177. * @param string $irid
  178. * @param string $con 附加获取收款条件 可以为空
  179. * @return unknown[]|mixed[]|string[]
  180. */
  181. public function getInvoiceReceivablesByIrid($irid = "",$con="") {
  182. Doo::loadClass ( 'XDeode' );
  183. $XDeode = new XDeode ( 5 );
  184. $irid = $this->authcode ( $irid );
  185. $detail = array ();
  186. if (! empty ( $irid ) && is_numeric ( $irid ))
  187. $detail = $this->getOne ( array (
  188. 'where' => " irid=" . $irid.$con,
  189. 'asArray' => TRUE
  190. ) );
  191. $detail ['cid'] = '';
  192. $detail ['title'] = '';
  193. if ($detail ['receivablesCategory']!="PUBLIC"){
  194. $category = explode ( ":", $detail ['receivablesCategory'] );
  195. $detail ['cid'] = $category [0];
  196. $detail ['title'] = $category [1];
  197. }
  198. $detail ['sid'] = '';
  199. $detail ['username'] = '';
  200. if ($detail ['receivablesStaff']!="PUBLIC"){
  201. $staff = explode ( "-", $detail ['receivablesStaff'] );
  202. $detail ['sid'] = $staff [0];
  203. $detail ['username'] = $staff [1];
  204. }
  205. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  206. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  207. return $detail;
  208. }
  209. public function getInvoiceReceivablesByIrsid($irid = "", $sid = "") {
  210. Doo::loadClass ( 'XDeode' );
  211. $XDeode = new XDeode ( 5 );
  212. $irid = $XDeode->decode ( $irid );
  213. $detail = array ();
  214. if (! empty ( $irid ) && is_numeric ( $irid )) {
  215. $detail = $this->getOne ( array (
  216. 'where' => " irid=" . $irid . " and receivablesStaff like '" . $sid . "_%'",
  217. 'asArray' => TRUE
  218. ) );
  219. $detail ['sid'] = '';
  220. $detail ['username'] = '';
  221. if (! empty ( $detail ['receivablesStaff'] )) {
  222. $staff = explode ( "-", $detail ['receivablesStaff'] );
  223. $detail ['sid'] = $staff [0];
  224. $detail ['username'] = $staff [1];
  225. }
  226. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  227. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  228. }
  229. return $detail;
  230. }
  231. /**
  232. * 添加一个收款
  233. * @param array $item 收款相关数据
  234. * @return number 返回收款ID
  235. */
  236. public function addInvoiceReceivables($item = array()) {
  237. $lid = 0;
  238. if (is_array ( $item ) && ! empty ( $item )) {
  239. foreach ( $item as $key => $value ) {
  240. $this->$key = $value;
  241. }
  242. $lid = $this->insert ();
  243. }
  244. return $lid;
  245. }
  246. /**
  247. * 根据参数字段更新相应字段(主键ID必须传)
  248. * @param array $item 相关需要更新的字段信息
  249. * @return number 返回发票ID
  250. */
  251. public function setInvoiceReceivablesByCondition($item = array()) {
  252. $lid = 0;
  253. if (is_array ( $item ) && ! empty ( $item )) {
  254. foreach ( $item as $key => $value ) {
  255. $this->$key = $value;
  256. }
  257. $lid = $this->update ();
  258. }
  259. return $lid;
  260. }
  261. /**
  262. * 根据irid 获取一组收款数据
  263. * @param string $irid
  264. * @return unknown
  265. */
  266. public function getInvoiceReceivablesInIrid($irid = '') {
  267. if (empty($irid))
  268. return array();
  269. $list = $this->find ( array (
  270. 'where' => " irid in(" . $irid . ")",
  271. 'asArray' => TRUE
  272. ) );
  273. foreach ($list as $key=>$value){
  274. }
  275. return $list;
  276. }
  277. function getReceivablesByUntreadStatusPage($limit = 0, $con = "", $desc = 'desc') {
  278. if (empty ( $limit ))
  279. return array ();
  280. $list = $this->find ( array (
  281. 'where' => $con,//" bindStatus=1 and receivablesStaff like '" . $sid . "_%' ".$con,
  282. 'limit' => $limit,
  283. $desc => 'irid',
  284. 'asArray' => TRUE
  285. ) );
  286. Doo::loadClass ( 'XDeode' );
  287. $XDeode = new XDeode ( 5 );
  288. Doo::loadModel ( 'invoice' );
  289. $invoice = new invoice ();
  290. Doo::loadModel ( 'invoiceROLog' );
  291. $invoiceROLog = new invoiceROLog ();
  292. foreach ( $list as $key => $value ) {
  293. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  294. $list [$key] ['iridKey'] = $this->authcode ( $value ['irid'],'' );
  295. if (isset($value ['iid'])&&!empty($value ['iid'])){
  296. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  297. $list [$key] ['irList'] = $invoice->getInvoiceByIid( $value ['iid'] );
  298. }else{
  299. $list [$key] ['iidKeyK']='';
  300. $list [$key] ['irList']=array('invoiceSerial'=>'');
  301. }
  302. $list [$key]['irolg']=$invoiceROLog->getInvoiceROLogByIrid($value ['irid'],'desc');
  303. // $list [$key] ['sumPrice'] = 0;
  304. // if (! empty ( $list [$key] ['irList'] ))
  305. // $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
  306. // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  307. }
  308. return $list;
  309. }
  310. /**
  311. * 加密或解密指定字符串
  312. *
  313. * @param string $string 要加密或解密的字符串
  314. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  315. * @param string $key 加解密的key
  316. * @param $expiry 超时值
  317. *
  318. */
  319. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  320. $ckey_length = 4;
  321. if (! $key) {
  322. $key = $this->INVOICEKEY;
  323. }
  324. $key = md5 ( $key );
  325. $keya = md5 ( substr ( $key, 0, 16 ) );
  326. $keyb = md5 ( substr ( $key, 16, 16 ) );
  327. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  328. $cryptkey = $keya . md5 ( $keya . $keyc );
  329. $key_length = strlen ( $cryptkey );
  330. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  331. $string_length = strlen ( $string );
  332. $result = '';
  333. $box = range ( 0, 255 );
  334. $rndkey = array ();
  335. for($i = 0; $i <= 255; $i ++) {
  336. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  337. }
  338. for($j = $i = 0; $i < 256; $i ++) {
  339. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  340. $tmp = $box [$i];
  341. $box [$i] = $box [$j];
  342. $box [$j] = $tmp;
  343. }
  344. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  345. $a = ($a + 1) % 256;
  346. $j = ($j + $box [$a]) % 256;
  347. $tmp = $box [$a];
  348. $box [$a] = $box [$j];
  349. $box [$j] = $tmp;
  350. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  351. }
  352. if ($operation == 'DECODE') {
  353. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  354. return substr ( $result, 26 );
  355. } else {
  356. return '';
  357. }
  358. } else {
  359. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  360. }
  361. }
  362. }
  363. ?>