invoiceReceivables.php 17 KB

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