invoiceReceivables.php 13 KB

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