invoiceReceivables.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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 $receivablesPrice;
  18. public $receivablesSerial;
  19. public $receivablesMessage;
  20. public $receivablesBank;
  21. public $receivablesDate;
  22. public $receivablesCategory;
  23. public $receivablesStaff;
  24. public $recepitTitleMark;
  25. public $inputStaff;
  26. public $inputType;
  27. public $source;
  28. public $date;
  29. public $confirmTime;
  30. public $bindDate;
  31. public $unbundlingTime;
  32. public $accountClerk;
  33. public $sourcePrice;
  34. public $_table = 'CLD_invoiceReceivables';
  35. public $_primarykey = 'irid';
  36. public $_fields = array (
  37. 'irid',
  38. 'bindStatus',
  39. 'untreadStatus',
  40. 'untreadStaff',
  41. 'iid',
  42. 'receivablesPrice',
  43. 'receivablesSerial',
  44. 'receivablesMessage',
  45. 'receivablesBank',
  46. 'receivablesDate',
  47. 'receivablesCategory',
  48. 'receivablesStaff',
  49. 'recepitTitleMark',
  50. 'inputStaff',
  51. 'inputType',
  52. 'source',
  53. 'date',
  54. 'confirmTime',
  55. 'bindDate',
  56. 'unbundlingTime',
  57. 'accountClerk' ,
  58. 'sourcePrice'
  59. );
  60. public function getSumOfReceivablesPrice($iridString = "") {
  61. if (empty ( $iridString ))
  62. return 0;
  63. $list = $this->getOne ( array (
  64. 'select' => ' sum(receivablesPrice) as receivablesPrice ',
  65. 'where' => " irid IN ( " . $iridString . " )",
  66. 'groupby' => 'iid',
  67. 'asArray' => TRUE
  68. ) );
  69. //echo " irid in ( " . $iridString . " )";
  70. //echo $list ['receivablesPrice'].'sdsdf';
  71. if (empty ( $list ))
  72. return 0;
  73. return $list ['receivablesPrice'];
  74. }
  75. /**
  76. * 获取最新几条收款包括最新的一条操作日志
  77. * @param number $limit
  78. * @return unknown
  79. */
  80. public function getInvoiceReceivablesByNew($limit = 4, $con = "") {
  81. if (empty ( $con ))
  82. return array ();
  83. $list = $this->find ( array (
  84. 'where' => $con,
  85. 'desc' => 'irid',
  86. 'limit' => $limit,
  87. 'asArray' => TRUE
  88. ) );
  89. Doo::loadModel ( 'invoiceROLog' );
  90. $invoiceROLog = new invoiceROLog ();
  91. Doo::loadModel ( 'invoice' );
  92. $invoice = new invoice ();
  93. foreach ( $list as $key => $value ) {
  94. $list [$key] ['invoiceROLog'] = $invoiceROLog->getInvoiceROLogByIrid ( $value ['irid'], 'desc' );
  95. $list [$key] ['invoiceDetail'] = $invoice->getInvoiceByIid ( $value ['iid'] );
  96. }
  97. return $list;
  98. }
  99. /**
  100. * 获得最近录入发票,不包含已经绑定的
  101. */
  102. public function getInvoiceReceivablesByInput() {
  103. $list = $this->find ( array (
  104. 'where' => "bindStatus=0",
  105. 'desc' => 'irid',
  106. 'asArray' => TRUE
  107. ) );
  108. foreach ( $list as $key => $value ) {
  109. $list [$key] ['receivablesCategory'] = explode ( ':', $value ['receivablesCategory'] );
  110. if ($value ['receivablesStaff'] != 'PUBLIC')
  111. $list [$key] ['receivablesStaff'] = explode ( '-', $value ['receivablesStaff'] );
  112. $list [$key] ['iridKey'] = $this->authcode ( $value ['irid'], '' );
  113. }
  114. return $list;
  115. }
  116. public function getInvoiceReceivablesByClaim($cid = 0, $sid = 0) {
  117. if (! empty ( $cid )) {
  118. $list ['csClaim'] = $this->find ( array (
  119. 'where' => "receivablesCategory='public' and receivablesStaff='public' and bindStatus=0",
  120. 'desc' => 'irid',
  121. 'asArray' => TRUE
  122. ) );
  123. foreach ( $list ['csClaim'] as $key => $value ) {
  124. $list ['csClaim'] [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  125. // $list ['csClaim'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  126. }
  127. $list ['sClaim'] = $this->find ( array (
  128. 'where' => "receivablesCategory!='public' and receivablesStaff='public' and receivablesCategory like '" . $cid . ":%' and bindStatus=0",
  129. 'desc' => 'irid',
  130. 'asArray' => TRUE
  131. ) );
  132. foreach ( $list ['sClaim'] as $key => $value ) {
  133. $list ['sClaim'] [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  134. }
  135. }
  136. if (! empty ( $cid ) && ! empty ( $sid )) {
  137. $list ['arClaim'] = $this->find ( array ( // and receivablesCategory like '" . $cid . ":%'
  138. 'where' => "receivablesCategory!='public' and receivablesStaff!='public' and receivablesStaff like '" . $sid . "-%' and bindStatus=0",
  139. 'desc' => 'irid',
  140. 'asArray' => TRUE
  141. ) );
  142. foreach ( $list ['arClaim'] as $key => $value ) {
  143. $staff = explode ( "-", $value ['receivablesStaff'] );
  144. $list ['arClaim'] [$key] ['sid'] = $staff [0];
  145. $list ['arClaim'] [$key] ['username'] = $staff [1];
  146. }
  147. $list ['myClaim'] = $this->find ( array (
  148. 'where' => " receivablesStaff like '" . $sid . "-%' and receivablesCategory like '" . $cid . ":%' and bindStatus=0",
  149. 'desc' => 'irid',
  150. 'asArray' => TRUE
  151. ) );
  152. foreach ( $list ['myClaim'] as $key => $value ) {
  153. $list ['myClaim'] [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  154. $staff = explode ( "-", $value ['receivablesStaff'] );
  155. $list ['myClaim'] [$key] ['sid'] = $staff [0];
  156. $list ['myClaim'] [$key] ['username'] = $staff [1];
  157. }
  158. $list ['bindClaim'] = $this->find ( array (
  159. 'where' => " bindStatus=1 and receivablesStaff like '" . $sid . "-%' ",
  160. 'desc' => 'irid',
  161. 'limit' => 3,
  162. 'asArray' => TRUE
  163. ) );
  164. Doo::loadModel ( 'invoice' );
  165. $invoice = new invoice ();
  166. Doo::loadClass ( 'XDeode' );
  167. $XDeode = new XDeode ( 5 );
  168. //print_r($list ['bindClaim']);
  169. foreach ( $list ['bindClaim'] as $key => $value ) {
  170. $id = $invoice->getInvoiceByIid ( $value ['iid'] );
  171. $id ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  172. $list ['bindClaim'] [$key] ['invoice'] = $id;
  173. $list ['bindClaim'] [$key] ['iridKeyUrl'] = $XDeode->encode ( $value ['irid'] );
  174. }
  175. }
  176. return $list;
  177. }
  178. /**
  179. * 根据发票ID和绑定状态获得收款数据,绑定状态为ALL获取所有状态数据
  180. * @param string $iid 发票ID
  181. * @param string $bindStatus
  182. * @return mixed
  183. */
  184. public function getInvoiceReceivablesByIid($iid = "", $bindStatus = "All") {
  185. Doo::loadClass ( 'XDeode' );
  186. $XDeode = new XDeode ( 5 );
  187. $iid = $this->authcode ( $iid );
  188. $list = array ();
  189. if (! empty ( $iid ) && is_numeric ( $iid )) {
  190. $sql = '';
  191. if ($bindStatus == 1)
  192. $sql = " and bindStatus=1";
  193. elseif ($bindStatus === 0)
  194. $sql = " and bindStatus=0";
  195. $list = $this->find ( array (
  196. 'where' => " iid=" . $iid . $sql,
  197. 'asArray' => TRUE
  198. ) );
  199. }
  200. foreach ( $list as $key => $value ) {
  201. $list [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  202. $staff = explode ( "-", $value ['receivablesStaff'] );
  203. $list [$key] ['sid'] = $staff [0];
  204. $list [$key] ['username'] = $staff [1];
  205. $list [$key] ['iridKey'] = $XDeode->encode ( $value ['irid'] );
  206. }
  207. return $list;
  208. }
  209. public function getInvoiceReceivablesInIridString($iridString = "") {
  210. $list = array ();
  211. if (! empty ( $iridString ))
  212. $list = $this->find ( array (
  213. 'where' => " irid in ( " . $iridString . " )",
  214. 'asArray' => TRUE
  215. ) );
  216. $price = 0;
  217. $serial = 0;
  218. Doo::loadClass ( 'XDeode' );
  219. $XDeode = new XDeode ( 5 );
  220. foreach ( $list as $key => $value ) {
  221. $price += $value ['receivablesPrice'];
  222. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  223. }
  224. if (! empty ( $list ))
  225. $list [0] ['sumPrice'] = $price;
  226. return $list;
  227. }
  228. /**
  229. * 根据收款ID获取一条相关数据
  230. * @param string $irid
  231. * @param string $con 附加获取收款条件 可以为空
  232. * @return unknown[]|mixed[]|string[]
  233. */
  234. public function getInvoiceReceivablesByIrid($irid = "", $con = "") {
  235. Doo::loadClass ( 'XDeode' );
  236. $XDeode = new XDeode ( 5 );
  237. if (! is_numeric ( $irid ))
  238. $irid = $this->authcode ( $irid );
  239. $detail = array ();
  240. if (! empty ( $irid ) && is_numeric ( $irid ))
  241. $detail = $this->getOne ( array (
  242. 'where' => " irid=" . $irid . $con,
  243. 'asArray' => TRUE
  244. ) );
  245. if (empty ( $detail ))
  246. return $detail;
  247. $detail ['cid'] = '';
  248. $detail ['title'] = '';
  249. if ($detail ['receivablesCategory'] != "PUBLIC") {
  250. $category = explode ( ":", $detail ['receivablesCategory'] );
  251. $detail ['cid'] = $category [0];
  252. $detail ['title'] = $category [1];
  253. }
  254. $detail ['sid'] = '';
  255. $detail ['username'] = '';
  256. if ($detail ['receivablesStaff'] != "PUBLIC") {
  257. $staff = explode ( "-", $detail ['receivablesStaff'] );
  258. $detail ['sid'] = $staff [0];
  259. $detail ['username'] = $staff [1];
  260. }
  261. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  262. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  263. return $detail;
  264. }
  265. public function getInvoiceReceivablesByIrsid($irid = "", $sid = "") {
  266. Doo::loadClass ( 'XDeode' );
  267. $XDeode = new XDeode ( 5 );
  268. $irid = $XDeode->decode ( $irid );
  269. $detail = array ();
  270. if (! empty ( $irid ) && is_numeric ( $irid )) {
  271. if (! empty ( $sid ))
  272. $detail = $this->getOne ( array (
  273. 'where' => " irid=" . $irid . " and receivablesStaff like '" . $sid . "_%'",
  274. 'asArray' => TRUE
  275. ) );
  276. else
  277. $detail = $this->getOne ( array (
  278. 'where' => " irid=" . $irid ,
  279. 'asArray' => TRUE
  280. ) );
  281. $detail ['sid'] = '';
  282. $detail ['username'] = '';
  283. if (! empty ( $detail ['receivablesStaff'] )) {
  284. $staff = explode ( "-", $detail ['receivablesStaff'] );
  285. $detail ['sid'] = $staff [0];
  286. $detail ['username'] = $staff [1];
  287. }
  288. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  289. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  290. }
  291. return $detail;
  292. }
  293. /**
  294. * 添加一个收款
  295. * @param array $item 收款相关数据
  296. * @return number 返回收款ID
  297. */
  298. public function addInvoiceReceivables($item = array()) {
  299. $lid = 0;
  300. if (is_array ( $item ) && ! empty ( $item )) {
  301. foreach ( $item as $key => $value ) {
  302. $this->$key = $value;
  303. }
  304. $lid = $this->insert ();
  305. }
  306. return $lid;
  307. }
  308. /**
  309. * 根据参数字段更新相应字段(主键ID必须传)
  310. * @param array $item 相关需要更新的字段信息
  311. * @return number 返回发票ID
  312. */
  313. public function setInvoiceReceivablesByCondition($item = array()) {
  314. $lid = 0;
  315. if (is_array ( $item ) && ! empty ( $item )) {
  316. foreach ( $item as $key => $value ) {
  317. $this->$key = $value;
  318. }
  319. $lid = $this->update ();
  320. }
  321. return $lid;
  322. }
  323. /**
  324. * 根据irid 获取一组收款数据
  325. * @param string $irid
  326. * @return unknown
  327. */
  328. public function getInvoiceReceivablesInIrid($irid = '') {
  329. if (empty ( $irid ))
  330. return array ();
  331. $list = $this->find ( array (
  332. 'where' => " irid in(" . $irid . ")",
  333. 'asArray' => TRUE
  334. ) );
  335. foreach ( $list as $key => $value ) {
  336. }
  337. return $list;
  338. }
  339. function getReceivablesByUntreadStatusPage($limit = 0, $con = "", $desc = 'desc', $descField = 'irid') {
  340. if (empty ( $limit ))
  341. return array ();
  342. $list = $this->find ( array (
  343. 'where' => $con, // " bindStatus=1 and receivablesStaff like '" . $sid . "_%' ".$con,
  344. 'limit' => $limit,
  345. $desc => $descField,
  346. 'asArray' => TRUE
  347. ) );
  348. Doo::loadClass ( 'XDeode' );
  349. $XDeode = new XDeode ( 5 );
  350. Doo::loadModel ( 'invoice' );
  351. $invoice = new invoice ();
  352. Doo::loadModel ( 'invoiceROLog' );
  353. $invoiceROLog = new invoiceROLog ();
  354. foreach ( $list as $key => $value ) {
  355. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  356. $list [$key] ['iridKey'] = $this->authcode ( $value ['irid'], '' );
  357. if (isset ( $value ['iid'] ) && ! empty ( $value ['iid'] )) {
  358. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  359. $list [$key] ['irList'] = $invoice->getInvoiceByIid ( $value ['iid'] );
  360. } else {
  361. $list [$key] ['iidKeyK'] = '';
  362. $list [$key] ['irList'] = array (
  363. 'invoiceSerial' => ''
  364. );
  365. }
  366. $list [$key] ['irolg'] = $invoiceROLog->getInvoiceROLogByIrid ( $value ['irid'], 'desc' );
  367. // $list [$key] ['sumPrice'] = 0;
  368. // if (! empty ( $list [$key] ['irList'] ))
  369. // $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
  370. // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  371. }
  372. return $list;
  373. }
  374. function delInvoiceReceivablesByIrid($irid = 0) {
  375. if (! empty ( $irid ) && is_numeric ( $irid ))
  376. $this->delete ( array (
  377. 'where' => 'irid=' . $irid
  378. ) );
  379. }
  380. /**
  381. * 加密或解密指定字符串
  382. *
  383. * @param string $string 要加密或解密的字符串
  384. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  385. * @param string $key 加解密的key
  386. * @param $expiry 超时值
  387. *
  388. */
  389. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  390. $ckey_length = 4;
  391. if (! $key) {
  392. $key = $this->INVOICEKEY;
  393. }
  394. $key = md5 ( $key );
  395. $keya = md5 ( substr ( $key, 0, 16 ) );
  396. $keyb = md5 ( substr ( $key, 16, 16 ) );
  397. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  398. $cryptkey = $keya . md5 ( $keya . $keyc );
  399. $key_length = strlen ( $cryptkey );
  400. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  401. $string_length = strlen ( $string );
  402. $result = '';
  403. $box = range ( 0, 255 );
  404. $rndkey = array ();
  405. for($i = 0; $i <= 255; $i ++) {
  406. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  407. }
  408. for($j = $i = 0; $i < 256; $i ++) {
  409. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  410. $tmp = $box [$i];
  411. $box [$i] = $box [$j];
  412. $box [$j] = $tmp;
  413. }
  414. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  415. $a = ($a + 1) % 256;
  416. $j = ($j + $box [$a]) % 256;
  417. $tmp = $box [$a];
  418. $box [$a] = $box [$j];
  419. $box [$j] = $tmp;
  420. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  421. }
  422. if ($operation == 'DECODE') {
  423. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  424. return substr ( $result, 26 );
  425. } else {
  426. return '';
  427. }
  428. } else {
  429. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  430. }
  431. }
  432. }
  433. ?>