invoiceReceivables.php 14 KB

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