invoiceReceivables.php 13 KB

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