invoiceReceivables.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. foreach ( $list ['bindClaim'] as $key => $value ) {
  168. $id = $invoice->getInvoiceByIid ( $value ['iid'] );
  169. $id ['iidKeyUrl'] = $XDeode->encode ( $id ['iid'] );
  170. $list ['bindClaim'] [$key] ['invoice'] = $id;
  171. $list ['bindClaim'] [$key] ['iridKeyUrl'] = $XDeode->encode ( $value ['irid'] );
  172. }
  173. }
  174. return $list;
  175. }
  176. /**
  177. * 根据发票ID和绑定状态获得收款数据,绑定状态为ALL获取所有状态数据
  178. * @param string $iid 发票ID
  179. * @param string $bindStatus
  180. * @return mixed
  181. */
  182. public function getInvoiceReceivablesByIid($iid = "", $bindStatus = "All") {
  183. Doo::loadClass ( 'XDeode' );
  184. $XDeode = new XDeode ( 5 );
  185. $iid = $this->authcode ( $iid );
  186. $list = array ();
  187. if (! empty ( $iid ) && is_numeric ( $iid )) {
  188. $sql = '';
  189. if ($bindStatus == 1)
  190. $sql = " and bindStatus=1";
  191. elseif ($bindStatus === 0)
  192. $sql = " and bindStatus=0";
  193. $list = $this->find ( array (
  194. 'where' => " iid=" . $iid . $sql,
  195. 'asArray' => TRUE
  196. ) );
  197. }
  198. foreach ( $list as $key => $value ) {
  199. $list [$key] ['iidKey'] = $this->authcode ( $value ['irid'], '' );
  200. $staff = explode ( "-", $value ['receivablesStaff'] );
  201. $list [$key] ['sid'] = $staff [0];
  202. $list [$key] ['username'] = $staff [1];
  203. $list [$key] ['iridKey'] = $XDeode->encode ( $value ['irid'] );
  204. }
  205. return $list;
  206. }
  207. public function getInvoiceReceivablesInIridString($iridString = "") {
  208. $list = array ();
  209. if (! empty ( $iridString ))
  210. $list = $this->find ( array (
  211. 'where' => " irid in ( " . $iridString . " )",
  212. 'asArray' => TRUE
  213. ) );
  214. $price = 0;
  215. $serial = 0;
  216. Doo::loadClass ( 'XDeode' );
  217. $XDeode = new XDeode ( 5 );
  218. foreach ( $list as $key => $value ) {
  219. $price += $value ['receivablesPrice'];
  220. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  221. }
  222. if (! empty ( $list ))
  223. $list [0] ['sumPrice'] = $price;
  224. return $list;
  225. }
  226. /**
  227. * 根据收款ID获取一条相关数据
  228. * @param string $irid
  229. * @param string $con 附加获取收款条件 可以为空
  230. * @return unknown[]|mixed[]|string[]
  231. */
  232. public function getInvoiceReceivablesByIrid($irid = "", $con = "") {
  233. Doo::loadClass ( 'XDeode' );
  234. $XDeode = new XDeode ( 5 );
  235. if (! is_numeric ( $irid ))
  236. $irid = $this->authcode ( $irid );
  237. $detail = array ();
  238. if (! empty ( $irid ) && is_numeric ( $irid ))
  239. $detail = $this->getOne ( array (
  240. 'where' => " irid=" . $irid . $con,
  241. 'asArray' => TRUE
  242. ) );
  243. if (empty ( $detail ))
  244. return $detail;
  245. $detail ['cid'] = '';
  246. $detail ['title'] = '';
  247. if ($detail ['receivablesCategory'] != "PUBLIC") {
  248. $category = explode ( ":", $detail ['receivablesCategory'] );
  249. $detail ['cid'] = $category [0];
  250. $detail ['title'] = $category [1];
  251. }
  252. $detail ['sid'] = '';
  253. $detail ['username'] = '';
  254. if ($detail ['receivablesStaff'] != "PUBLIC") {
  255. $staff = explode ( "-", $detail ['receivablesStaff'] );
  256. $detail ['sid'] = $staff [0];
  257. $detail ['username'] = $staff [1];
  258. }
  259. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  260. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  261. return $detail;
  262. }
  263. public function getInvoiceReceivablesByIrsid($irid = "", $sid = "") {
  264. Doo::loadClass ( 'XDeode' );
  265. $XDeode = new XDeode ( 5 );
  266. $irid = $XDeode->decode ( $irid );
  267. $detail = array ();
  268. if (! empty ( $irid ) && is_numeric ( $irid )) {
  269. if (! empty ( $sid ))
  270. $detail = $this->getOne ( array (
  271. 'where' => " irid=" . $irid . " and receivablesStaff like '" . $sid . "_%'",
  272. 'asArray' => TRUE
  273. ) );
  274. else
  275. $detail = $this->getOne ( array (
  276. 'where' => " irid=" . $irid ,
  277. 'asArray' => TRUE
  278. ) );
  279. $detail ['sid'] = '';
  280. $detail ['username'] = '';
  281. if (! empty ( $detail ['receivablesStaff'] )) {
  282. $staff = explode ( "-", $detail ['receivablesStaff'] );
  283. $detail ['sid'] = $staff [0];
  284. $detail ['username'] = $staff [1];
  285. }
  286. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  287. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  288. }
  289. return $detail;
  290. }
  291. /**
  292. * 添加一个收款
  293. * @param array $item 收款相关数据
  294. * @return number 返回收款ID
  295. */
  296. public function addInvoiceReceivables($item = array()) {
  297. $lid = 0;
  298. if (is_array ( $item ) && ! empty ( $item )) {
  299. foreach ( $item as $key => $value ) {
  300. $this->$key = $value;
  301. }
  302. $lid = $this->insert ();
  303. }
  304. return $lid;
  305. }
  306. /**
  307. * 根据参数字段更新相应字段(主键ID必须传)
  308. * @param array $item 相关需要更新的字段信息
  309. * @return number 返回发票ID
  310. */
  311. public function setInvoiceReceivablesByCondition($item = array()) {
  312. $lid = 0;
  313. if (is_array ( $item ) && ! empty ( $item )) {
  314. foreach ( $item as $key => $value ) {
  315. $this->$key = $value;
  316. }
  317. $lid = $this->update ();
  318. }
  319. return $lid;
  320. }
  321. /**
  322. * 根据irid 获取一组收款数据
  323. * @param string $irid
  324. * @return unknown
  325. */
  326. public function getInvoiceReceivablesInIrid($irid = '') {
  327. if (empty ( $irid ))
  328. return array ();
  329. $list = $this->find ( array (
  330. 'where' => " irid in(" . $irid . ")",
  331. 'asArray' => TRUE
  332. ) );
  333. foreach ( $list as $key => $value ) {
  334. }
  335. return $list;
  336. }
  337. function getReceivablesByUntreadStatusPage($limit = 0, $con = "", $desc = 'desc', $descField = 'irid') {
  338. if (empty ( $limit ))
  339. return array ();
  340. $list = $this->find ( array (
  341. 'where' => $con, // " bindStatus=1 and receivablesStaff like '" . $sid . "_%' ".$con,
  342. 'limit' => $limit,
  343. $desc => $descField,
  344. 'asArray' => TRUE
  345. ) );
  346. Doo::loadClass ( 'XDeode' );
  347. $XDeode = new XDeode ( 5 );
  348. Doo::loadModel ( 'invoice' );
  349. $invoice = new invoice ();
  350. Doo::loadModel ( 'invoiceROLog' );
  351. $invoiceROLog = new invoiceROLog ();
  352. foreach ( $list as $key => $value ) {
  353. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  354. $list [$key] ['iridKey'] = $this->authcode ( $value ['irid'], '' );
  355. if (isset ( $value ['iid'] ) && ! empty ( $value ['iid'] )) {
  356. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  357. $list [$key] ['irList'] = $invoice->getInvoiceByIid ( $value ['iid'] );
  358. } else {
  359. $list [$key] ['iidKeyK'] = '';
  360. $list [$key] ['irList'] = array (
  361. 'invoiceSerial' => ''
  362. );
  363. }
  364. $list [$key] ['irolg'] = $invoiceROLog->getInvoiceROLogByIrid ( $value ['irid'], 'desc' );
  365. // $list [$key] ['sumPrice'] = 0;
  366. // if (! empty ( $list [$key] ['irList'] ))
  367. // $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
  368. // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  369. }
  370. return $list;
  371. }
  372. function delInvoiceReceivablesByIrid($irid = 0) {
  373. if (! empty ( $irid ) && is_numeric ( $irid ))
  374. $this->delete ( array (
  375. 'where' => 'irid=' . $irid
  376. ) );
  377. }
  378. /**
  379. * 加密或解密指定字符串
  380. *
  381. * @param string $string 要加密或解密的字符串
  382. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  383. * @param string $key 加解密的key
  384. * @param $expiry 超时值
  385. *
  386. */
  387. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  388. $ckey_length = 4;
  389. if (! $key) {
  390. $key = $this->INVOICEKEY;
  391. }
  392. $key = md5 ( $key );
  393. $keya = md5 ( substr ( $key, 0, 16 ) );
  394. $keyb = md5 ( substr ( $key, 16, 16 ) );
  395. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  396. $cryptkey = $keya . md5 ( $keya . $keyc );
  397. $key_length = strlen ( $cryptkey );
  398. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  399. $string_length = strlen ( $string );
  400. $result = '';
  401. $box = range ( 0, 255 );
  402. $rndkey = array ();
  403. for($i = 0; $i <= 255; $i ++) {
  404. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  405. }
  406. for($j = $i = 0; $i < 256; $i ++) {
  407. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  408. $tmp = $box [$i];
  409. $box [$i] = $box [$j];
  410. $box [$j] = $tmp;
  411. }
  412. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  413. $a = ($a + 1) % 256;
  414. $j = ($j + $box [$a]) % 256;
  415. $tmp = $box [$a];
  416. $box [$a] = $box [$j];
  417. $box [$j] = $tmp;
  418. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  419. }
  420. if ($operation == 'DECODE') {
  421. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  422. return substr ( $result, 26 );
  423. } else {
  424. return '';
  425. }
  426. } else {
  427. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  428. }
  429. }
  430. }
  431. ?>