invoiceReceivables.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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. $detail = $this->getOne ( array (
  267. 'where' => " irid=" . $irid . " and receivablesStaff like '" . $sid . "_%'",
  268. 'asArray' => TRUE
  269. ) );
  270. $detail ['sid'] = '';
  271. $detail ['username'] = '';
  272. if (! empty ( $detail ['receivablesStaff'] )) {
  273. $staff = explode ( "-", $detail ['receivablesStaff'] );
  274. $detail ['sid'] = $staff [0];
  275. $detail ['username'] = $staff [1];
  276. }
  277. $detail ['iridKey'] = $XDeode->encode ( $detail ['irid'] );
  278. $detail ['iridEn'] = $this->authcode ( $detail ['irid'], '' );
  279. }
  280. return $detail;
  281. }
  282. /**
  283. * 添加一个收款
  284. * @param array $item 收款相关数据
  285. * @return number 返回收款ID
  286. */
  287. public function addInvoiceReceivables($item = array()) {
  288. $lid = 0;
  289. if (is_array ( $item ) && ! empty ( $item )) {
  290. foreach ( $item as $key => $value ) {
  291. $this->$key = $value;
  292. }
  293. $lid = $this->insert ();
  294. }
  295. return $lid;
  296. }
  297. /**
  298. * 根据参数字段更新相应字段(主键ID必须传)
  299. * @param array $item 相关需要更新的字段信息
  300. * @return number 返回发票ID
  301. */
  302. public function setInvoiceReceivablesByCondition($item = array()) {
  303. $lid = 0;
  304. if (is_array ( $item ) && ! empty ( $item )) {
  305. foreach ( $item as $key => $value ) {
  306. $this->$key = $value;
  307. }
  308. $lid = $this->update ();
  309. }
  310. return $lid;
  311. }
  312. /**
  313. * 根据irid 获取一组收款数据
  314. * @param string $irid
  315. * @return unknown
  316. */
  317. public function getInvoiceReceivablesInIrid($irid = '') {
  318. if (empty ( $irid ))
  319. return array ();
  320. $list = $this->find ( array (
  321. 'where' => " irid in(" . $irid . ")",
  322. 'asArray' => TRUE
  323. ) );
  324. foreach ( $list as $key => $value ) {
  325. }
  326. return $list;
  327. }
  328. function getReceivablesByUntreadStatusPage($limit = 0, $con = "", $desc = 'desc', $descField = 'irid') {
  329. if (empty ( $limit ))
  330. return array ();
  331. $list = $this->find ( array (
  332. 'where' => $con, // " bindStatus=1 and receivablesStaff like '" . $sid . "_%' ".$con,
  333. 'limit' => $limit,
  334. $desc => $descField,
  335. 'asArray' => TRUE
  336. ) );
  337. Doo::loadClass ( 'XDeode' );
  338. $XDeode = new XDeode ( 5 );
  339. Doo::loadModel ( 'invoice' );
  340. $invoice = new invoice ();
  341. Doo::loadModel ( 'invoiceROLog' );
  342. $invoiceROLog = new invoiceROLog ();
  343. foreach ( $list as $key => $value ) {
  344. $list [$key] ['iridKeyK'] = $XDeode->encode ( $value ['irid'] );
  345. $list [$key] ['iridKey'] = $this->authcode ( $value ['irid'], '' );
  346. if (isset ( $value ['iid'] ) && ! empty ( $value ['iid'] )) {
  347. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  348. $list [$key] ['irList'] = $invoice->getInvoiceByIid ( $value ['iid'] );
  349. } else {
  350. $list [$key] ['iidKeyK'] = '';
  351. $list [$key] ['irList'] = array (
  352. 'invoiceSerial' => ''
  353. );
  354. }
  355. $list [$key] ['irolg'] = $invoiceROLog->getInvoiceROLogByIrid ( $value ['irid'], 'desc' );
  356. // $list [$key] ['sumPrice'] = 0;
  357. // if (! empty ( $list [$key] ['irList'] ))
  358. // $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
  359. // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  360. }
  361. return $list;
  362. }
  363. function delInvoiceReceivablesByIrid($irid = 0) {
  364. if (! empty ( $irid ) && is_numeric ( $irid ))
  365. $this->delete ( array (
  366. 'where' => 'irid=' . $irid
  367. ) );
  368. }
  369. /**
  370. * 加密或解密指定字符串
  371. *
  372. * @param string $string 要加密或解密的字符串
  373. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  374. * @param string $key 加解密的key
  375. * @param $expiry 超时值
  376. *
  377. */
  378. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  379. $ckey_length = 4;
  380. if (! $key) {
  381. $key = $this->INVOICEKEY;
  382. }
  383. $key = md5 ( $key );
  384. $keya = md5 ( substr ( $key, 0, 16 ) );
  385. $keyb = md5 ( substr ( $key, 16, 16 ) );
  386. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  387. $cryptkey = $keya . md5 ( $keya . $keyc );
  388. $key_length = strlen ( $cryptkey );
  389. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  390. $string_length = strlen ( $string );
  391. $result = '';
  392. $box = range ( 0, 255 );
  393. $rndkey = array ();
  394. for($i = 0; $i <= 255; $i ++) {
  395. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  396. }
  397. for($j = $i = 0; $i < 256; $i ++) {
  398. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  399. $tmp = $box [$i];
  400. $box [$i] = $box [$j];
  401. $box [$j] = $tmp;
  402. }
  403. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  404. $a = ($a + 1) % 256;
  405. $j = ($j + $box [$a]) % 256;
  406. $tmp = $box [$a];
  407. $box [$a] = $box [$j];
  408. $box [$j] = $tmp;
  409. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  410. }
  411. if ($operation == 'DECODE') {
  412. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  413. return substr ( $result, 26 );
  414. } else {
  415. return '';
  416. }
  417. } else {
  418. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  419. }
  420. }
  421. }
  422. ?>