invoiceReceivables.php 23 KB

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