invoiceReceivables.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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 or a.iidExtend!="") 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='' or bankBatchNumber is NULL)",
  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. //待修改
  297. public function getInvoiceReceivablesInIridString($iridString = "") {
  298. $list = array ();
  299. if (! empty ( $iridString ))
  300. $list = $this->find ( array (
  301. 'where' => " irid in ( " . $iridString . " )",
  302. 'asArray' => TRUE
  303. ) );
  304. $price = 0;
  305. $serial = 0;
  306. Doo::loadClass ( 'XDeode' );
  307. $XDeode = new XDeode ( 5 );
  308. foreach ( $list as $key => $value ) {
  309. $price += $value ['receivablesPrice'];
  310. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  311. }
  312. if (! empty ( $list ))
  313. $list [0] ['sumPrice'] = $price;
  314. return $list;
  315. }
  316. /**
  317. * 根据收款ID获取一条相关数据
  318. * @param string $irid
  319. * @param string $con 附加获取收款条件 可以为空
  320. * @return unknown[]|mixed[]|string[]
  321. */
  322. public function getInvoiceReceivablesByIrid($irid = "", $con = "") {
  323. Doo::loadClass ( 'XDeode' );
  324. $XDeode = new XDeode ( 5 );
  325. if (! is_numeric ( $irid ))
  326. $irid = $this->authcode ( $irid );
  327. $detail = array ();
  328. if (! empty ( $irid ) && is_numeric ( $irid ))
  329. $detail = $this->getOne ( array (
  330. 'where' => " irid=" . $irid . $con,
  331. 'asArray' => TRUE
  332. ) );
  333. if (empty ( $detail ))
  334. return $detail;
  335. $detail ['cid'] = '';
  336. $detail ['title'] = '';
  337. if ($detail ['receivablesCategory'] != "PUBLIC") {
  338. $category = explode ( ":", $detail ['receivablesCategory'] );
  339. $detail ['cid'] = $category [0];
  340. $detail ['title'] = $category [1];
  341. }
  342. $detail ['sid'] = '';
  343. $detail ['username'] = '';
  344. if ($detail ['receivablesStaff'] != "PUBLIC") {
  345. $staff = explode ( "-", $detail ['receivablesStaff'] );
  346. $detail ['sid'] = $staff [0];
  347. $detail ['username'] = $staff [1];
  348. }
  349. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  350. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  351. return $detail;
  352. }
  353. /**
  354. * 获得一组irid的收款
  355. * @param string $iridList
  356. * @param string $con
  357. * @return unknown|string[]|unknown[]|mixed[]
  358. */
  359. public function getInvoiceReceivablesByIridList($iridList = "", $con = "") {
  360. Doo::loadClass ( 'XDeode' );
  361. $XDeode = new XDeode ( 5 );
  362. $list = array ();
  363. if (! empty ( $iridList )) {
  364. $list = $this->find ( array (
  365. 'where' => " irid in( " . $iridList." ) " . $con,
  366. 'asArray' => TRUE
  367. ) );
  368. }
  369. if (empty ( $list )){
  370. return $list;
  371. }
  372. foreach ($list as $key=>$value){
  373. $list [$key] ['cid'] = '';
  374. $list [$key] ['title'] = '';
  375. if ($list [$key] ['receivablesCategory'] != "PUBLIC") {
  376. $category = explode ( ":", $list [$key] ['receivablesCategory'] );
  377. $list [$key] ['cid'] = $category [0];
  378. $list [$key] ['title'] = $category [1];
  379. }
  380. $list [$key] ['sid'] = '';
  381. $list [$key] ['username'] = '';
  382. if ($list [$key] ['receivablesStaff'] != "PUBLIC") {
  383. $staff = explode ( "-", $list [$key] ['receivablesStaff'] );
  384. $list [$key] ['sid'] = $staff [0];
  385. $list [$key] ['username'] = $staff [1];
  386. }
  387. $list [$key] ['iridKey'] = $XDeode->encode ( $list [$key] ['irid'] );
  388. $list [$key] ['iridEn'] = $this->authcode ( $list [$key] ['irid'], '' );
  389. }
  390. return $list;
  391. }
  392. /**
  393. * 根据收款序列号获取一条相关数据
  394. * @param string $irid
  395. * @param string $con 附加获取收款条件 可以为空
  396. * @return unknown[]|mixed[]|string[]
  397. */
  398. public function getInvoiceReceivablesBySerial($receivablesSerial = "", $con = "") {
  399. Doo::loadClass ( 'XDeode' );
  400. $XDeode = new XDeode ( 5 );
  401. if (! empty ( $receivablesSerial ))
  402. $detail = $this->getOne ( array (
  403. 'where' => " receivablesSerial like '%" . $receivablesSerial . "%'" . $con,
  404. 'limit' => 1,
  405. 'asArray' => TRUE
  406. ) );
  407. if (empty ( $detail ))
  408. return $detail;
  409. $detail ['cid'] = '';
  410. $detail ['title'] = '';
  411. if ($detail ['receivablesCategory'] != "PUBLIC") {
  412. $category = explode ( ":", $detail ['receivablesCategory'] );
  413. $detail ['cid'] = $category [0];
  414. $detail ['title'] = $category [1];
  415. }
  416. $detail ['sid'] = '';
  417. $detail ['username'] = '';
  418. if ($detail ['receivablesStaff'] != "PUBLIC") {
  419. $staff = explode ( "-", $detail ['receivablesStaff'] );
  420. $detail ['sid'] = $staff [0];
  421. $detail ['username'] = $staff [1];
  422. }
  423. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  424. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  425. return $detail;
  426. }
  427. public function getInvoiceReceivablesByIrsid($irid = "", $sid = "") {
  428. Doo::loadClass ( 'XDeode' );
  429. $XDeode = new XDeode ( 5 );
  430. $irid = $XDeode->decode ( $irid );
  431. $detail = array ();
  432. if (! empty ( $irid ) && is_numeric ( $irid )) {
  433. if (! empty ( $sid ))
  434. $detail = $this->getOne ( array (
  435. 'where' => " irid=" . $irid . " and receivablesStaff like '" . $sid . "_%'",
  436. 'asArray' => TRUE
  437. ) );
  438. else
  439. $detail = $this->getOne ( array (
  440. 'where' => " irid=" . $irid,
  441. 'asArray' => TRUE
  442. ) );
  443. $detail ['sid'] = '';
  444. $detail ['username'] = ''; //
  445. if (! empty ( $detail ['receivablesStaff'] ) && $detail ['receivablesStaff'] != 'PUBLIC') {
  446. $staff = explode ( "-", $detail ['receivablesStaff'] );
  447. $detail ['sid'] = $staff [0];
  448. $detail ['username'] = $staff [1];
  449. }
  450. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  451. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  452. }
  453. return $detail;
  454. }
  455. /**
  456. * 添加一个收款
  457. * @param array $item 收款相关数据
  458. * @return number 返回收款ID
  459. */
  460. public function addInvoiceReceivables($item = array()) {
  461. $lid = 0;
  462. if (is_array ( $item ) && ! empty ( $item )) {
  463. foreach ( $item as $key => $value ) {
  464. $this->$key = $value;
  465. }
  466. $lid = $this->insert ();
  467. }
  468. return $lid;
  469. }
  470. /**
  471. * 根据参数字段更新相应字段(主键ID必须传)
  472. * @param array $item 相关需要更新的字段信息
  473. * @return number 返回发票ID
  474. */
  475. public function setInvoiceReceivablesByCondition($item = array()) {
  476. $lid = 0;
  477. if (is_array ( $item ) && ! empty ( $item )) {
  478. foreach ( $item as $key => $value ) {
  479. $this->$key = $value;
  480. }
  481. $lid = $this->update ();
  482. }
  483. return $lid;
  484. }
  485. /**
  486. * 根据irid 获取一组收款数据
  487. * @param string $irid
  488. * @return unknown
  489. */
  490. public function getInvoiceReceivablesInIrid($irid = '') {
  491. if (empty ( $irid ))
  492. return array ();
  493. $list = $this->find ( array (
  494. 'where' => " irid in(" . $irid . ")",
  495. 'asArray' => TRUE
  496. ) );
  497. foreach ( $list as $key => $value ) {
  498. }
  499. return $list;
  500. }
  501. function getInvoiceReceivablesByConditionPage($limit = 0, $con = "", $desc = 'desc', $descField = 'irid') {
  502. if (empty ( $limit ))
  503. return array ();
  504. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId ,a.*,b.invoicePrice
  505. // from ' . $this->_table . ' as a left join CLD_invoice as b on
  506. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  507. // where ' . $con . ' group by a.irid ORDER BY ' . $descField . ' ' . $desc . ' limit ' . $limit . '
  508. // ';
  509. // echo $sql;
  510. $sql='select * from '.$this->_table.' as a where '.$con.' ORDER BY '.$descField.' '.$desc.' limit '.$limit;
  511. //echo $sql;
  512. $query = Doo::db ()->query ( $sql );
  513. $list = $query->fetchAll ();
  514. //获得收款关联的发票数据
  515. $iidList=array();$iidString='';
  516. foreach ($list as $key=>$value){
  517. array_push($iidList, $value['iid'].$value['iidExtend']);
  518. }
  519. $iidString=implode(',', $iidList);
  520. $invoiceList=array();
  521. if(!empty($iidString)){
  522. $sql='select invoiceSerial,iid,irid from CLD_invoice where iid in ('.$iidString.') ';
  523. $query = Doo::db ()->query ( $sql );
  524. $invoiceList = $query->fetchAll ();
  525. }
  526. //echo $sql;
  527. Doo::loadClass ( 'XDeode' );
  528. $XDeode = new XDeode ( 5 );
  529. Doo::loadModel ( 'invoiceROLog' );
  530. $invoiceROLog = new invoiceROLog ();
  531. foreach ( $list as $key => $value ) {
  532. $list [$key] ['invoiceList']=$tem=array();
  533. foreach ($invoiceList as $ilK=>$ilv){
  534. //发票绑定了多个收款的情况
  535. $iridList=explode(",", $ilv['irid']);
  536. foreach ($iridList as $irlv){
  537. if($value['irid']==$irlv){
  538. $tem[$XDeode->encode ($ilv['iid'])]= $ilv['invoiceSerial'];
  539. break;
  540. }
  541. }
  542. }
  543. $list [$key] ['invoiceList']=$tem;
  544. // $invoiceSerial = explode ( ',', $value ['invoiceSerial'] );
  545. // $invoiceId = explode ( ",", $value ['invoiceId'] );
  546. // if (empty ( $invoiceSerial [0] ))
  547. // $list [$key] ['invoiceList'] = array ();
  548. // else {
  549. // foreach ( $invoiceId as $k => $v ) {
  550. // if (! empty ( $v ))
  551. // $invoiceId [$k] = $XDeode->encode ( $v );
  552. // }
  553. // $list [$key] ['invoiceList'] = array_combine ( $invoiceId, $invoiceSerial );
  554. // }
  555. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  556. $list [$key] ['iridKey'] = $this->authcode ( $value ['irid'], '' );
  557. $list [$key] ['irolg'] = $invoiceROLog->getInvoiceROLogByIrid ( $value ['irid'], 'desc' );
  558. }
  559. // print_r($list);
  560. return $list;
  561. }
  562. function getReceivablesByUntreadStatusPage($limit = 0, $con = "", $desc = 'desc', $descField = 'irid') {
  563. if (empty ( $limit ))
  564. return array ();
  565. $list = $this->find ( array (
  566. 'where' => $con, // " bindStatus=1 and receivablesStaff like '" . $sid . "_%' ".$con,
  567. 'limit' => $limit,
  568. $desc => $descField,
  569. 'asArray' => TRUE
  570. ) );
  571. Doo::loadClass ( 'XDeode' );
  572. $XDeode = new XDeode ( 5 );
  573. Doo::loadModel ( 'invoice' );
  574. $invoice = new invoice ();
  575. Doo::loadModel ( 'invoiceROLog' );
  576. $invoiceROLog = new invoiceROLog ();
  577. foreach ( $list as $key => $value ) {
  578. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  579. $list [$key] ['iridKey'] = $this->authcode ( $value ['irid'], '' );
  580. if (isset ( $value ['iid'] ) && ! empty ( $value ['iid'] )) {
  581. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  582. $list [$key] ['irList'] = $invoice->getInvoiceByIid ( $value ['iid'] );
  583. } else {
  584. $list [$key] ['iidKeyK'] = '';
  585. $list [$key] ['irList'] = array (
  586. 'invoiceSerial' => ''
  587. );
  588. }
  589. $list [$key] ['irolg'] = $invoiceROLog->getInvoiceROLogByIrid ( $value ['irid'], 'desc' );
  590. // $list [$key] ['sumPrice'] = 0;
  591. // if (! empty ( $list [$key] ['irList'] ))
  592. // $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
  593. // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  594. }
  595. return $list;
  596. }
  597. function delInvoiceReceivablesByIrid($irid = 0) {
  598. if (! empty ( $irid ) && is_numeric ( $irid ))
  599. $this->delete ( array (
  600. 'where' => 'irid=' . $irid
  601. ) );
  602. }
  603. /**
  604. * 加密或解密指定字符串
  605. *
  606. * @param string $string 要加密或解密的字符串
  607. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  608. * @param string $key 加解密的key
  609. * @param $expiry 超时值
  610. *
  611. */
  612. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  613. $ckey_length = 4;
  614. if (! $key) {
  615. $key = $this->INVOICEKEY;
  616. }
  617. $key = md5 ( $key );
  618. $keya = md5 ( substr ( $key, 0, 16 ) );
  619. $keyb = md5 ( substr ( $key, 16, 16 ) );
  620. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  621. $cryptkey = $keya . md5 ( $keya . $keyc );
  622. $key_length = strlen ( $cryptkey );
  623. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  624. $string_length = strlen ( $string );
  625. $result = '';
  626. $box = range ( 0, 255 );
  627. $rndkey = array ();
  628. for($i = 0; $i <= 255; $i ++) {
  629. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  630. }
  631. for($j = $i = 0; $i < 256; $i ++) {
  632. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  633. $tmp = $box [$i];
  634. $box [$i] = $box [$j];
  635. $box [$j] = $tmp;
  636. }
  637. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  638. $a = ($a + 1) % 256;
  639. $j = ($j + $box [$a]) % 256;
  640. $tmp = $box [$a];
  641. $box [$a] = $box [$j];
  642. $box [$j] = $tmp;
  643. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  644. }
  645. if ($operation == 'DECODE') {
  646. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  647. return substr ( $result, 26 );
  648. } else {
  649. return '';
  650. }
  651. } else {
  652. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  653. }
  654. }
  655. }
  656. ?>