invoiceReceivables.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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 $untreadStatus;
  15. public $untreadStaff;
  16. public $iid;
  17. public $iidExtend;
  18. public $bindPrice;
  19. public $receivablesPrice;
  20. public $OriginalPrice;
  21. public $receivablesSerial;
  22. public $receivablesMessage;
  23. public $receivablesBank;
  24. public $receivablesDate;
  25. public $receivablesCategory;
  26. public $receivablesStaff;
  27. public $recepitTitleMark;
  28. public $inputStaff;
  29. public $inputType;
  30. public $source;
  31. public $date;
  32. public $confirmTime;
  33. public $bindDate;
  34. public $unbundlingTime;
  35. public $accountClerk;
  36. public $sourcePrice;
  37. public $bankBatchNumber;
  38. public $refundType;
  39. public $refundCompany;
  40. public $refundNumber;
  41. public $refundPrice;
  42. public $refundRemarks;
  43. public $refundLog;
  44. public $relationIrid;
  45. public $relationLog;
  46. public $_table = 'CLD_invoiceReceivables';
  47. public $_primarykey = 'irid';
  48. public $_fields = array (
  49. 'irid',
  50. 'bindStatus',
  51. 'untreadStatus',
  52. 'untreadStaff',
  53. 'iid',
  54. 'iidExtend',
  55. 'bindPrice',
  56. 'receivablesPrice',
  57. 'OriginalPrice',
  58. 'receivablesSerial',
  59. 'receivablesMessage',
  60. 'receivablesBank',
  61. 'receivablesDate',
  62. 'receivablesCategory',
  63. 'receivablesStaff',
  64. 'recepitTitleMark',
  65. 'inputStaff',
  66. 'inputType',
  67. 'source',
  68. 'date',
  69. 'confirmTime',
  70. 'bindDate',
  71. 'unbundlingTime',
  72. 'accountClerk',
  73. 'sourcePrice',
  74. 'bankBatchNumber',
  75. 'refundType',
  76. 'refundCompany',
  77. 'refundNumber',
  78. 'refundPrice',
  79. 'refundRemarks',
  80. 'refundLog',
  81. 'relationIrid',
  82. 'relationLog'
  83. );
  84. public function getSumOfReceivablesPrice($iridString = "") {
  85. if (empty ( $iridString ))
  86. return 0;
  87. $list = $this->getOne ( array (
  88. 'select' => ' sum(receivablesPrice) as receivablesPrice ',
  89. 'where' => " irid IN ( " . $iridString . " )",
  90. 'groupby' => 'iid',
  91. 'asArray' => TRUE
  92. ) );
  93. if (empty ( $list ))
  94. return 0;
  95. return $list ['receivablesPrice'];
  96. }
  97. /**
  98. * 获取最新几条收款包括最新的一条操作日志
  99. * @param number $limit
  100. * @return unknown
  101. */
  102. public function getInvoiceReceivablesByNew($limit = 4, $con = "") {
  103. if (empty ( $con ))
  104. return array ();
  105. $list = $this->find ( array (
  106. 'where' => $con,
  107. 'desc' => 'irid',
  108. 'limit' => $limit,
  109. 'asArray' => TRUE
  110. ) );
  111. Doo::loadModel ( 'invoiceROLog' );
  112. $invoiceROLog = new invoiceROLog ();
  113. Doo::loadModel ( 'invoice' );
  114. $invoice = new invoice ();
  115. foreach ( $list as $key => $value ) {
  116. $list [$key] ['invoiceROLog'] = $invoiceROLog->getInvoiceROLogByIrid ( $value ['irid'], 'desc' );
  117. $list [$key] ['invoiceDetail'] = $invoice->getInvoiceByIid ( $value ['iid'] );
  118. }
  119. return $list;
  120. }
  121. public function getInvoiceReceivablesByBBN($bankBatchNumber = "") {
  122. if (empty ( $bankBatchNumber ))
  123. return array ();
  124. $list = $this->find ( array (
  125. 'where' => "bankBatchNumber= '" . $bankBatchNumber . "'",
  126. 'asArray' => TRUE
  127. ) );
  128. return $list;
  129. }
  130. /**
  131. * 获得最近录入发票,不包含已经绑定的
  132. */
  133. public function getInvoiceReceivablesByInput() {
  134. Doo::loadClass ( 'XDeode' );
  135. $XDeode = new XDeode ( 5 );
  136. $list = $this->find ( array (
  137. 'where' => "bindStatus=0 and iid=0",
  138. 'desc' => 'irid',
  139. 'asArray' => TRUE
  140. ) );
  141. foreach ( $list as $key => $value ) {
  142. if ($value ['receivablesCategory'] != 'PUBLIC')
  143. $list [$key] ['receivablesCategory'] = explode ( ':', $value ['receivablesCategory'] );
  144. $list [$key] ['iridKeyXD'] = $XDeode->encode ( $value ['irid'] );
  145. if ($value ['receivablesStaff'] != 'PUBLIC')
  146. $list [$key] ['receivablesStaff'] = explode ( '-', $value ['receivablesStaff'] );
  147. $list [$key] ['iridKey'] = $this->authcode ( $value ['irid'], '' );
  148. }
  149. return $list;
  150. }
  151. /**
  152. * 获得部分入账的收款
  153. */
  154. function getInvoiceReceivablesByHalf() {
  155. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId ,a.*
  156. from ' . $this->_table . ' as a left join CLD_invoice as b on
  157. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  158. where a.bindStatus=0 and a.iid!=0 GROUP BY a.irid
  159. ';
  160. $query = Doo::db ()->query ( $sql );
  161. $list = $query->fetchAll ();
  162. if (empty ( $list ))
  163. return array ();
  164. if ($list [0] ['irid'] == NULL) {
  165. return array ();
  166. }
  167. Doo::loadClass ( 'XDeode' );
  168. $XDeode = new XDeode ( 5 );
  169. foreach ( $list as $key => $value ) {
  170. $list [$key] ['uPrice'] = $value ['receivablesPrice'] - $value ['bindPrice'];
  171. $invoiceSerial = explode ( ',', $value ['invoiceSerial'] );
  172. $invoiceId = explode ( ",", $value ['invoiceId'] );
  173. foreach ( $invoiceId as $k => $v ) {
  174. $invoiceId [$k] = $XDeode->encode ( $v );
  175. }
  176. $list [$key] ['invoiceList'] = array_combine ( $invoiceId, $invoiceSerial );
  177. $list [$key] ['iridAuthKey'] = $this->authcode ( $value ['irid'], '' );
  178. }
  179. return $list;
  180. }
  181. public function getInvoiceReceivablesByClaim($cid = 0, $sid = 0) {
  182. Doo::loadClass ( 'XDeode' );
  183. $XDeode = new XDeode ( 5 );
  184. if (! empty ( $cid )) {
  185. $list ['csClaim'] = $this->find ( array (
  186. 'where' => "receivablesCategory='public' and receivablesStaff='public' and bindStatus=0 and bankBatchNumber=''",
  187. 'desc' => 'irid',
  188. 'asArray' => TRUE
  189. ) );
  190. foreach ( $list ['csClaim'] as $key => $value ) {
  191. $list ['csClaim'] [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  192. // $list ['csClaim'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  193. }
  194. $list ['sClaim'] = $this->find ( array (
  195. 'where' => "receivablesCategory!='public' and receivablesStaff='public' and receivablesCategory like '" . $cid . ":%' and bindStatus=0",
  196. 'desc' => 'irid',
  197. 'asArray' => TRUE
  198. ) );
  199. foreach ( $list ['sClaim'] as $key => $value ) {
  200. $list ['sClaim'] [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  201. }
  202. }
  203. if (! empty ( $cid ) && ! empty ( $sid )) {
  204. $list ['arClaim'] = $this->find ( array ( // and receivablesCategory like '" . $cid . ":%'
  205. 'where' => "receivablesCategory!='public' and receivablesStaff!='public' and receivablesStaff like '" . $sid . "-%' and bindStatus=0",
  206. 'desc' => 'irid',
  207. 'asArray' => TRUE
  208. ) );
  209. foreach ( $list ['arClaim'] as $key => $value ) {
  210. $staff = explode ( "-", $value ['receivablesStaff'] );
  211. $list ['arClaim'] [$key] ['sid'] = $staff [0];
  212. $list ['arClaim'] [$key] ['username'] = $staff [1];
  213. $list ['arClaim'] [$key] ['iridKey'] = $XDeode->encode ( $value ['irid'] );
  214. }
  215. $list ['myClaim'] = $this->find ( array (
  216. 'where' => " receivablesStaff like '" . $sid . "-%' and receivablesCategory like '" . $cid . ":%' and bindStatus=0",
  217. 'desc' => 'irid',
  218. 'asArray' => TRUE
  219. ) );
  220. foreach ( $list ['myClaim'] as $key => $value ) {
  221. $list ['myClaim'] [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  222. $staff = explode ( "-", $value ['receivablesStaff'] );
  223. $list ['myClaim'] [$key] ['sid'] = $staff [0];
  224. $list ['myClaim'] [$key] ['username'] = $staff [1];
  225. }
  226. $list ['bindClaim'] = $this->find ( array (
  227. 'where' => " bindStatus=1 and receivablesStaff like '" . $sid . "-%' ",
  228. 'desc' => 'irid',
  229. 'limit' => 3,
  230. 'asArray' => TRUE
  231. ) );
  232. Doo::loadModel ( 'invoice' );
  233. $invoice = new invoice ();
  234. Doo::loadClass ( 'XDeode' );
  235. $XDeode = new XDeode ( 5 );
  236. // print_r($list ['bindClaim']);
  237. foreach ( $list ['bindClaim'] as $key => $value ) {
  238. $id = $invoice->getInvoiceByIid ( $value ['iid'] );
  239. $id ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  240. $list ['bindClaim'] [$key] ['invoice'] = $id;
  241. $list ['bindClaim'] [$key] ['iridKeyUrl'] = $XDeode->encode ( $value ['irid'] );
  242. }
  243. }
  244. return $list;
  245. }
  246. /**
  247. * 根据发票ID和绑定状态获得收款数据,绑定状态为ALL获取所有状态数据
  248. * @param string $iid 发票ID
  249. * @param string $bindStatus
  250. * @return mixed
  251. */
  252. public function getInvoiceReceivablesByIid($iid = "", $bindStatus = "All") {
  253. Doo::loadClass ( 'XDeode' );
  254. $XDeode = new XDeode ( 5 );
  255. $iid = $this->authcode ( $iid );
  256. $list = array ();
  257. if (! empty ( $iid ) && is_numeric ( $iid )) {
  258. $sql = '';
  259. if ($bindStatus == 1)
  260. $sql = " and bindStatus=1";
  261. elseif ($bindStatus === 0)
  262. $sql = " and bindStatus=0";
  263. $list = $this->find ( array (
  264. 'where' => " iid=" . $iid . $sql,
  265. 'asArray' => TRUE
  266. ) );
  267. }
  268. foreach ( $list as $key => $value ) {
  269. $list [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  270. $staff = explode ( "-", $value ['receivablesStaff'] );
  271. $list [$key] ['sid'] = $staff [0];
  272. $list [$key] ['username'] = $staff [1];
  273. $list [$key] ['iridKey'] = $XDeode->encode ( $value ['irid'] );
  274. }
  275. return $list;
  276. }
  277. public function getInvoiceReceivablesInIridString($iridString = "") {
  278. $list = array ();
  279. if (! empty ( $iridString ))
  280. $list = $this->find ( array (
  281. 'where' => " irid in ( " . $iridString . " )",
  282. 'asArray' => TRUE
  283. ) );
  284. $price = 0;
  285. $serial = 0;
  286. Doo::loadClass ( 'XDeode' );
  287. $XDeode = new XDeode ( 5 );
  288. foreach ( $list as $key => $value ) {
  289. $price += $value ['receivablesPrice'];
  290. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  291. }
  292. if (! empty ( $list ))
  293. $list [0] ['sumPrice'] = $price;
  294. return $list;
  295. }
  296. /**
  297. * 根据收款ID获取一条相关数据
  298. * @param string $irid
  299. * @param string $con 附加获取收款条件 可以为空
  300. * @return unknown[]|mixed[]|string[]
  301. */
  302. public function getInvoiceReceivablesByIrid($irid = "", $con = "") {
  303. Doo::loadClass ( 'XDeode' );
  304. $XDeode = new XDeode ( 5 );
  305. if (! is_numeric ( $irid ))
  306. $irid = $this->authcode ( $irid );
  307. $detail = array ();
  308. if (! empty ( $irid ) && is_numeric ( $irid ))
  309. $detail = $this->getOne ( array (
  310. 'where' => " irid=" . $irid . $con,
  311. 'asArray' => TRUE
  312. ) );
  313. if (empty ( $detail ))
  314. return $detail;
  315. $detail ['cid'] = '';
  316. $detail ['title'] = '';
  317. if ($detail ['receivablesCategory'] != "PUBLIC") {
  318. $category = explode ( ":", $detail ['receivablesCategory'] );
  319. $detail ['cid'] = $category [0];
  320. $detail ['title'] = $category [1];
  321. }
  322. $detail ['sid'] = '';
  323. $detail ['username'] = '';
  324. if ($detail ['receivablesStaff'] != "PUBLIC") {
  325. $staff = explode ( "-", $detail ['receivablesStaff'] );
  326. $detail ['sid'] = $staff [0];
  327. $detail ['username'] = $staff [1];
  328. }
  329. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  330. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  331. return $detail;
  332. }
  333. /**
  334. * 获得一组irid的收款
  335. * @param string $iridList
  336. * @param string $con
  337. * @return unknown|string[]|unknown[]|mixed[]
  338. */
  339. public function getInvoiceReceivablesByIridList($iridList = "", $con = "") {
  340. Doo::loadClass ( 'XDeode' );
  341. $XDeode = new XDeode ( 5 );
  342. $list = array ();
  343. if (! empty ( $iridList )) {
  344. $list = $this->find ( array (
  345. 'where' => " irid in( " . $iridList." ) " . $con,
  346. 'asArray' => TRUE
  347. ) );
  348. }
  349. if (empty ( $list )){
  350. return $list;
  351. }
  352. foreach ($list as $key=>$value){
  353. $list [$key] ['cid'] = '';
  354. $list [$key] ['title'] = '';
  355. if ($list [$key] ['receivablesCategory'] != "PUBLIC") {
  356. $category = explode ( ":", $list [$key] ['receivablesCategory'] );
  357. $list [$key] ['cid'] = $category [0];
  358. $list [$key] ['title'] = $category [1];
  359. }
  360. $list [$key] ['sid'] = '';
  361. $list [$key] ['username'] = '';
  362. if ($list [$key] ['receivablesStaff'] != "PUBLIC") {
  363. $staff = explode ( "-", $list [$key] ['receivablesStaff'] );
  364. $list [$key] ['sid'] = $staff [0];
  365. $list [$key] ['username'] = $staff [1];
  366. }
  367. $list [$key] ['iridKey'] = $XDeode->encode ( $list [$key] ['irid'] );
  368. $list [$key] ['iridEn'] = $this->authcode ( $list [$key] ['irid'], '' );
  369. }
  370. return $list;
  371. }
  372. /**
  373. * 根据收款序列号获取一条相关数据
  374. * @param string $irid
  375. * @param string $con 附加获取收款条件 可以为空
  376. * @return unknown[]|mixed[]|string[]
  377. */
  378. public function getInvoiceReceivablesBySerial($receivablesSerial = "", $con = "") {
  379. Doo::loadClass ( 'XDeode' );
  380. $XDeode = new XDeode ( 5 );
  381. if (! empty ( $receivablesSerial ))
  382. $detail = $this->getOne ( array (
  383. 'where' => " receivablesSerial like '%" . $receivablesSerial . "%'" . $con,
  384. 'limit' => 1,
  385. 'asArray' => TRUE
  386. ) );
  387. if (empty ( $detail ))
  388. return $detail;
  389. $detail ['cid'] = '';
  390. $detail ['title'] = '';
  391. if ($detail ['receivablesCategory'] != "PUBLIC") {
  392. $category = explode ( ":", $detail ['receivablesCategory'] );
  393. $detail ['cid'] = $category [0];
  394. $detail ['title'] = $category [1];
  395. }
  396. $detail ['sid'] = '';
  397. $detail ['username'] = '';
  398. if ($detail ['receivablesStaff'] != "PUBLIC") {
  399. $staff = explode ( "-", $detail ['receivablesStaff'] );
  400. $detail ['sid'] = $staff [0];
  401. $detail ['username'] = $staff [1];
  402. }
  403. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  404. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  405. return $detail;
  406. }
  407. public function getInvoiceReceivablesByIrsid($irid = "", $sid = "") {
  408. Doo::loadClass ( 'XDeode' );
  409. $XDeode = new XDeode ( 5 );
  410. $irid = $XDeode->decode ( $irid );
  411. $detail = array ();
  412. if (! empty ( $irid ) && is_numeric ( $irid )) {
  413. if (! empty ( $sid ))
  414. $detail = $this->getOne ( array (
  415. 'where' => " irid=" . $irid . " and receivablesStaff like '" . $sid . "_%'",
  416. 'asArray' => TRUE
  417. ) );
  418. else
  419. $detail = $this->getOne ( array (
  420. 'where' => " irid=" . $irid,
  421. 'asArray' => TRUE
  422. ) );
  423. $detail ['sid'] = '';
  424. $detail ['username'] = ''; //
  425. if (! empty ( $detail ['receivablesStaff'] ) && $detail ['receivablesStaff'] != 'PUBLIC') {
  426. $staff = explode ( "-", $detail ['receivablesStaff'] );
  427. $detail ['sid'] = $staff [0];
  428. $detail ['username'] = $staff [1];
  429. }
  430. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  431. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  432. }
  433. return $detail;
  434. }
  435. /**
  436. * 添加一个收款
  437. * @param array $item 收款相关数据
  438. * @return number 返回收款ID
  439. */
  440. public function addInvoiceReceivables($item = array()) {
  441. $lid = 0;
  442. if (is_array ( $item ) && ! empty ( $item )) {
  443. foreach ( $item as $key => $value ) {
  444. $this->$key = $value;
  445. }
  446. $lid = $this->insert ();
  447. }
  448. return $lid;
  449. }
  450. /**
  451. * 根据参数字段更新相应字段(主键ID必须传)
  452. * @param array $item 相关需要更新的字段信息
  453. * @return number 返回发票ID
  454. */
  455. public function setInvoiceReceivablesByCondition($item = array()) {
  456. $lid = 0;
  457. if (is_array ( $item ) && ! empty ( $item )) {
  458. foreach ( $item as $key => $value ) {
  459. $this->$key = $value;
  460. }
  461. $lid = $this->update ();
  462. }
  463. return $lid;
  464. }
  465. /**
  466. * 根据irid 获取一组收款数据
  467. * @param string $irid
  468. * @return unknown
  469. */
  470. public function getInvoiceReceivablesInIrid($irid = '') {
  471. if (empty ( $irid ))
  472. return array ();
  473. $list = $this->find ( array (
  474. 'where' => " irid in(" . $irid . ")",
  475. 'asArray' => TRUE
  476. ) );
  477. foreach ( $list as $key => $value ) {
  478. }
  479. return $list;
  480. }
  481. function getInvoiceReceivablesByConditionPage($limit = 0, $con = "", $desc = 'desc', $descField = 'irid') {
  482. if (empty ( $limit ))
  483. return array ();
  484. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId ,a.*,b.invoicePrice
  485. // from ' . $this->_table . ' as a left join CLD_invoice as b on
  486. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  487. // where ' . $con . ' group by a.irid ORDER BY ' . $descField . ' ' . $desc . ' limit ' . $limit . '
  488. // ';
  489. if(!empty($con)){
  490. $con=' where '.$con;
  491. }
  492. $sql='select * from '.$this->_table.' as a '.$con.' ORDER BY '.$descField.' '.$desc.' limit '.$limit;
  493. $query = Doo::db ()->query ( $sql );
  494. $list = $query->fetchAll ();
  495. //获得收款关联的发票数据
  496. $iidList=array();$iidString='';
  497. foreach ($list as $key=>$value){
  498. array_push($iidList, $value['iid'].$value['iidExtend']);
  499. }
  500. $iidString=implode(',', $iidList);
  501. $sql='select invoiceSerial,iid,irid from CLD_invoice where iid in ('.$iidString.') ';
  502. $query = Doo::db ()->query ( $sql );
  503. $invoiceList = $query->fetchAll ();
  504. Doo::loadClass ( 'XDeode' );
  505. $XDeode = new XDeode ( 5 );
  506. Doo::loadModel ( 'invoiceROLog' );
  507. $invoiceROLog = new invoiceROLog ();
  508. foreach ( $list as $key => $value ) {
  509. $tem=array();
  510. foreach ($invoiceList as $ilK=>$ilv){
  511. if($value['irid']==$ilv['irid']){
  512. $tem[$XDeode->encode ($ilv['iid'])]= $ilv['invoiceSerial'];
  513. }
  514. }
  515. $list [$key] ['invoiceList']=$tem;
  516. // $invoiceSerial = explode ( ',', $value ['invoiceSerial'] );
  517. // $invoiceId = explode ( ",", $value ['invoiceId'] );
  518. // if (empty ( $invoiceSerial [0] ))
  519. // $list [$key] ['invoiceList'] = array ();
  520. // else {
  521. // foreach ( $invoiceId as $k => $v ) {
  522. // if (! empty ( $v ))
  523. // $invoiceId [$k] = $XDeode->encode ( $v );
  524. // }
  525. // $list [$key] ['invoiceList'] = array_combine ( $invoiceId, $invoiceSerial );
  526. // }
  527. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  528. $list [$key] ['iridKey'] = $this->authcode ( $value ['irid'], '' );
  529. $list [$key] ['irolg'] = $invoiceROLog->getInvoiceROLogByIrid ( $value ['irid'], 'desc' );
  530. }
  531. // print_r($list);
  532. return $list;
  533. }
  534. function getReceivablesByUntreadStatusPage($limit = 0, $con = "", $desc = 'desc', $descField = 'irid') {
  535. if (empty ( $limit ))
  536. return array ();
  537. $list = $this->find ( array (
  538. 'where' => $con, // " bindStatus=1 and receivablesStaff like '" . $sid . "_%' ".$con,
  539. 'limit' => $limit,
  540. $desc => $descField,
  541. 'asArray' => TRUE
  542. ) );
  543. Doo::loadClass ( 'XDeode' );
  544. $XDeode = new XDeode ( 5 );
  545. Doo::loadModel ( 'invoice' );
  546. $invoice = new invoice ();
  547. Doo::loadModel ( 'invoiceROLog' );
  548. $invoiceROLog = new invoiceROLog ();
  549. foreach ( $list as $key => $value ) {
  550. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  551. $list [$key] ['iridKey'] = $this->authcode ( $value ['irid'], '' );
  552. if (isset ( $value ['iid'] ) && ! empty ( $value ['iid'] )) {
  553. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  554. $list [$key] ['irList'] = $invoice->getInvoiceByIid ( $value ['iid'] );
  555. } else {
  556. $list [$key] ['iidKeyK'] = '';
  557. $list [$key] ['irList'] = array (
  558. 'invoiceSerial' => ''
  559. );
  560. }
  561. $list [$key] ['irolg'] = $invoiceROLog->getInvoiceROLogByIrid ( $value ['irid'], 'desc' );
  562. // $list [$key] ['sumPrice'] = 0;
  563. // if (! empty ( $list [$key] ['irList'] ))
  564. // $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
  565. // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  566. }
  567. return $list;
  568. }
  569. function delInvoiceReceivablesByIrid($irid = 0) {
  570. if (! empty ( $irid ) && is_numeric ( $irid ))
  571. $this->delete ( array (
  572. 'where' => 'irid=' . $irid
  573. ) );
  574. }
  575. /**
  576. * 加密或解密指定字符串
  577. *
  578. * @param string $string 要加密或解密的字符串
  579. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  580. * @param string $key 加解密的key
  581. * @param $expiry 超时值
  582. *
  583. */
  584. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  585. $ckey_length = 4;
  586. if (! $key) {
  587. $key = $this->INVOICEKEY;
  588. }
  589. $key = md5 ( $key );
  590. $keya = md5 ( substr ( $key, 0, 16 ) );
  591. $keyb = md5 ( substr ( $key, 16, 16 ) );
  592. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  593. $cryptkey = $keya . md5 ( $keya . $keyc );
  594. $key_length = strlen ( $cryptkey );
  595. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  596. $string_length = strlen ( $string );
  597. $result = '';
  598. $box = range ( 0, 255 );
  599. $rndkey = array ();
  600. for($i = 0; $i <= 255; $i ++) {
  601. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  602. }
  603. for($j = $i = 0; $i < 256; $i ++) {
  604. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  605. $tmp = $box [$i];
  606. $box [$i] = $box [$j];
  607. $box [$j] = $tmp;
  608. }
  609. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  610. $a = ($a + 1) % 256;
  611. $j = ($j + $box [$a]) % 256;
  612. $tmp = $box [$a];
  613. $box [$a] = $box [$j];
  614. $box [$j] = $tmp;
  615. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  616. }
  617. if ($operation == 'DECODE') {
  618. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  619. return substr ( $result, 26 );
  620. } else {
  621. return '';
  622. }
  623. } else {
  624. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  625. }
  626. }
  627. }
  628. ?>