invoiceReceivables.php 21 KB

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