invoiceReceivables.php 14 KB

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