invoiceReceivables.php 13 KB

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