invoice.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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 invoice extends DooModel {
  11. private $INVOICEKEY = "APPROVAL";
  12. private $FUZZY='FUZZY';
  13. private $EXACTLY="EXACTLY";
  14. /**
  15. *
  16. * @var integer $iid 发票ID
  17. */
  18. public $iid;
  19. /**
  20. *
  21. * @var integer $status 审批状态
  22. */
  23. public $status;
  24. /**
  25. *
  26. * @var string $invoiceManage 当前审批组人员
  27. */
  28. public $printStatus;
  29. public $postStatus;
  30. public $invoiceManage;
  31. /**
  32. *
  33. * @var string $pendingApprovals 当前需要审批的人
  34. */
  35. public $pendingApprovals;
  36. /**
  37. *
  38. * @var string $processApprovals 已经审批过的人员
  39. */
  40. public $processApprovals;
  41. /**
  42. *
  43. * @var string $invoiceSerial 发票单号
  44. */
  45. public $invoiceSerial;
  46. /**
  47. *
  48. * @var integer $invoicePrice 发票金额
  49. */
  50. public $invoicePrice;
  51. /**
  52. * 管理组人员:发票打印,
  53. * @var unknown
  54. */
  55. public $moldManage;
  56. /**
  57. *
  58. * @var integer $cid 办事处ID
  59. */
  60. public $cid;
  61. /**
  62. *
  63. * @var string $categoryName 办事处名称
  64. */
  65. public $categoryName;
  66. /**
  67. *
  68. * @var integer $sid 提交发票人ID
  69. */
  70. public $sid;
  71. /**
  72. *
  73. * @var string $userName 提交人名字
  74. */
  75. public $printer;
  76. public $userName;
  77. /**
  78. *
  79. * @var string $remark 备注
  80. */
  81. public $remark;
  82. /**
  83. *
  84. * @var string $invoiceElement 发票内容
  85. */
  86. public $invoiceElement;
  87. /**
  88. *
  89. * @var string $invoiceType 发票类型
  90. */
  91. public $invoiceType;
  92. /**
  93. *
  94. * @var string $invoiceTitle 发票抬头
  95. */
  96. public $invoiceTitle;
  97. /**
  98. *
  99. * @var string $invoiceCompany 开票公司
  100. */
  101. public $invoiceCompany;
  102. /**
  103. *
  104. * @var string $invoiceNo 发票号
  105. */
  106. public $invoiceNo;
  107. /**
  108. *
  109. * @var string $TIN 纳税人识别码
  110. */
  111. public $TIN;
  112. /**
  113. *
  114. * @var string $address 注册地址
  115. */
  116. public $address;
  117. /**
  118. *
  119. * @var string $phone 电话
  120. */
  121. public $phone;
  122. /**
  123. *
  124. * @var string $bank 开户银行
  125. */
  126. public $bank;
  127. /**
  128. *
  129. * @var string $bankAccount 银行账户
  130. */
  131. public $bankAccount;
  132. /**
  133. *
  134. * @var integer $doPost 邮寄
  135. */
  136. public $doPost;
  137. /**
  138. *
  139. * @var string $recipients 收件人
  140. */
  141. public $recipients;
  142. /**
  143. *
  144. * @var string $recipientsPhone 收件人电话
  145. */
  146. public $recipientsPhone;
  147. /**
  148. *
  149. * @var string $recipientsAddress 收件地址
  150. */
  151. public $recipientsAddress;
  152. /**
  153. *
  154. * @var string $mailItems 邮寄物品
  155. */
  156. public $mailItems;
  157. public $mailItemsJson;
  158. public $expressCompany;
  159. public $expressNumber;
  160. public $actualItems;
  161. public $poster;
  162. public $untreadReason;
  163. public $untreadPost;
  164. public $untreadCompany;
  165. public $untreadNumber;
  166. public $untreadItems;
  167. public $untreadStatus;
  168. public $irid;
  169. public $bindTime;
  170. /**
  171. *
  172. * @var date $date 提交时间
  173. */
  174. public $date;
  175. public $isDelete;
  176. /**
  177. *
  178. * @var date $updateTime 更新时间
  179. */
  180. public $updateTime;
  181. /**
  182. *
  183. * @var date $printTime 打印时间
  184. */
  185. public $printTime;
  186. public $postTime;
  187. public $_table = 'CLD_invoice';
  188. public $_primarykey = 'iid';
  189. public $_fields = array (
  190. 'iid',
  191. 'invoiceManage',
  192. 'pendingApprovals',
  193. 'processApprovals',
  194. 'invoiceSerial',
  195. 'status',
  196. 'printStatus',
  197. 'postStatus',
  198. 'untreadStatus',
  199. 'invoicePrice',
  200. 'moldManage',
  201. 'cid',
  202. 'categoryName',
  203. 'irid',
  204. 'remark',
  205. 'invoiceElement',
  206. 'invoiceType',
  207. 'invoiceTitle',
  208. 'invoiceCompany',
  209. 'invoiceNo',
  210. 'TIN',
  211. 'address',
  212. 'phone',
  213. 'bank',
  214. 'bankAccount',
  215. 'doPost',
  216. 'recipients',
  217. 'recipientsPhone',
  218. 'recipientsAddress',
  219. 'mailItems',
  220. 'mailItemsJson',
  221. 'expressCompany',
  222. 'expressNumber',
  223. 'actualItems',
  224. 'untreadReason',
  225. 'untreadPost',
  226. 'untreadCompany',
  227. 'untreadNumber',
  228. 'untreadItems',
  229. 'poster',
  230. 'sid',
  231. 'userName',
  232. 'printer',
  233. 'date',
  234. 'isDelete',
  235. 'updateTime',
  236. 'printTime',
  237. 'postTime',
  238. 'bindTime'
  239. );
  240. /**
  241. * 根据发票ID获取一条发票数据
  242. * @param number $iid 发票ID
  243. * @param number $select 需要获取的字段,为空获取全部数据
  244. * @return array|array() 返回发票数据
  245. */
  246. public function getInvoiceByIid($iid = 0, $select = "") {
  247. if (! is_numeric ( $iid ))
  248. $iid = $this->authcode ( $iid );
  249. $condition = array (
  250. 'where' => "iid=" . $iid,
  251. 'asArray' => TRUE
  252. );
  253. if (! empty ( $select ))
  254. $condition += array (
  255. 'select' => $select
  256. );
  257. $Detail = array ();
  258. if (is_numeric ( $iid ) && ! empty ( $iid ))
  259. $Detail = $this->getOne ( $condition );
  260. if (isset ( $Detail ['expressCompany'] ) && ! empty ( $Detail ['expressCompany'] )) {
  261. $express = explode ( ":", $Detail ['expressCompany'] );
  262. $Detail ['expressCompany'] = $express [0];
  263. $Detail ['expressCom'] = $express [1];
  264. } else {
  265. $Detail ['expressCompany'] = '';
  266. $Detail ['expressCom'] = '';
  267. }
  268. Doo::loadClass ( 'XDeode' );
  269. $XDeode = new XDeode ( 5 );
  270. $Detail ['iidKeyUrl'] =$XDeode->encode ( $Detail ['iid'] );
  271. $Detail ['iidKey'] = $this->authcode ( $Detail ['iid'], '' );
  272. Doo::loadModel ( 'L_category' );
  273. $lCategory = new L_category ();
  274. $Detail ['category'] = $lCategory->getCategory ();
  275. return $Detail;
  276. }
  277. /**
  278. * 根据标题或者开票单位获得相关信息 - 准确查询
  279. * @param string $title 查询条件
  280. * @param string $query 默认模糊查询
  281. */
  282. public function getInvoiceByTitle($title="",$query="FUZZY",$cond=''){
  283. $detail=array();
  284. if (!empty($title)){
  285. $condition = array (
  286. 'asArray' => TRUE
  287. );
  288. if ($query==$this->FUZZY)
  289. $condition += array (
  290. 'where' => " (invoiceTitle like '%" . $title . "%' or invoiceCompany '%" . $title . "%') ".$cond,
  291. );
  292. else
  293. $condition += array (
  294. 'where' => "(invoiceTitle = '" . $title . "' or invoiceCompany= '" . $title . "') " .$cond,
  295. );
  296. $detail = $this->getOne ( $condition );
  297. if (!empty($detail)){
  298. Doo::loadClass ( 'XDeode' );
  299. $XDeode = new XDeode ( 5 );
  300. $detail ['iidKey'] = $this->authcode ( $detail ['iid'], '' );
  301. $detail ['iidKeyXD'] = $XDeode->encode ( $detail ['iid'] );
  302. }
  303. }
  304. return $detail;
  305. }
  306. public function getInvoiceByIsid($iid = "", $sid = 0) {
  307. if (empty ( $iid ) || empty ( $sid ))
  308. return array ();
  309. Doo::loadClass ( 'XDeode' );
  310. $XDeode = new XDeode ( 5 );
  311. $iid = $XDeode->decode ( $iid );
  312. if (! is_numeric ( $iid ))
  313. return array ();
  314. $detail = $this->getOne ( array (
  315. 'where' => "iid= '" . $iid . "'", // and sid=".$sid,
  316. 'asArray' => TRUE
  317. ) );
  318. return $detail;
  319. }
  320. /**
  321. * 获取单个可以打印的发票数据
  322. * @param number $iid 发票id
  323. * @param number $select 需要获取的字段,为空获取全部数据
  324. * @return array|array() 返回发票数据
  325. */
  326. public function getInvoiceByPrint($iid = 0, $select = "") {
  327. $condition = array (
  328. 'where' => "iid= '" . $iid . "' and status=2",
  329. 'asArray' => TRUE
  330. );
  331. if (! empty ( $select ))
  332. $condition += array (
  333. 'select' => $select
  334. );
  335. $detail = array ();
  336. if (! empty ( $iid ) && is_numeric ( $iid ))
  337. $detail = $this->getOne ( $condition );
  338. return $detail;
  339. }
  340. /**
  341. * 添加一个发票并进入审批状态
  342. * @param array $item 发票相关数据
  343. * @return number 返回发票ID
  344. */
  345. public function addInvoice($item = array()) {
  346. $lid = 0;
  347. if (is_array ( $item ) && ! empty ( $item )) {
  348. foreach ( $item as $key => $value ) {
  349. $this->$key = $value;
  350. }
  351. $lid = $this->insert ();
  352. }
  353. return $lid;
  354. }
  355. /**
  356. * 根据参数字段更新相应字段(主键ID必须传)
  357. * @param array $item 相关需要更新的字段信息
  358. * @return number 返回发票ID
  359. */
  360. public function setInvoiceByCondition($item = array()) {
  361. $lid = 0;
  362. if (is_array ( $item ) && ! empty ( $item )) {
  363. foreach ( $item as $key => $value ) {
  364. $this->$key = $value;
  365. }
  366. $lid = $this->update ();
  367. }
  368. return $lid;
  369. }
  370. /**
  371. * 根据管理组和发票当前状态获得打印发票数据;其中当iid为空时获取所有发票数据,反之获取1条数据
  372. * @param number $sid 管理组人员ID
  373. * @param number $status 状态 为0时获取可以打印数据,为1时获取已经完成打印数据
  374. * @param number $iid 发票ID
  375. * @return array|array() 返回所有发票数据,当iid有值时返回一条数据
  376. */
  377. public function getPrintInvoiceByManage($sid = 0, $status = 0, $iid = 0) {
  378. $list = array ();
  379. if (! empty ( $sid ) && empty ( $iid ))
  380. $list = $this->find ( array (
  381. 'where' => "status=2 and printStatus=" . $status . " and moldManage like '%[\"" . $sid . "\",%'",
  382. 'desc' => 'iid',
  383. 'asArray' => TRUE
  384. ) );
  385. elseif (! empty ( $sid ) && ! empty ( $iid ))
  386. $list = $this->getOne ( array (
  387. 'where' => "status=2 and printStatus=" . $status . " and moldManage like '%[\"" . $sid . "\",%' and iid=" . $iid,
  388. 'asArray' => TRUE
  389. ) );
  390. return $list;
  391. }
  392. /**
  393. * 获得与我相关的发票数据,其中包含 处理中,待处理,最旧入账等数据;当iid有值时获取一条关于sid的发票
  394. * @param number $sid 用户ID
  395. * @param number $iid 发票ID
  396. * @return array|array()
  397. */
  398. public function getMyInvoice($sid = 0, $iid = 0) {
  399. Doo::loadModel ( 'invoiceOperationLog' );
  400. $invoiceOperationLog = new invoiceOperationLog ();
  401. Doo::loadClass ( 'XDeode' );
  402. $XDeode = new XDeode ( 5 );
  403. $list = array ();
  404. if (! empty ( $iid )) {
  405. $list = $this->getOne ( array (
  406. 'where' => " sid=" . $sid . " and iid=" . $iid,
  407. 'asArray' => TRUE
  408. ) );
  409. } elseif (! empty ( $sid ) && empty ( $iid )) {
  410. $list ['pendingInvoice'] = array ();
  411. $list ['handleInvoice'] = array ();
  412. $list ['pendingInvoice'] = $this->find ( array (//加入邮件中也为 处理中 已退票
  413. 'where' => "((status=1) or (status=2 and printStatus=0) or ( status=2 and printStatus=1 and untreadStatus=1 and untreadPost=1 and untreadNumber!='') or
  414. ( status=2 and printStatus=1 and untreadStatus=1 and untreadPost=0)
  415. or (postStatus=0 and doPost=1 and status=2) ) and sid=" . $sid,
  416. 'desc' => 'iid',
  417. 'asArray' => TRUE
  418. ) );
  419. foreach ( $list ['pendingInvoice'] as $key => $value ) {
  420. $list ['pendingInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  421. $list ['pendingInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  422. }
  423. $list ['handleInvoice'] = $this->find ( array (
  424. // 需求变更 -去除出票状态的数据 or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  425. //新加入退票中 需要邮寄的发票
  426. 'where' => "(status=3 or status=4 or (status=2 and printStatus=1 and untreadStatus=2 ) or ( status=2 and printStatus=1 and untreadStatus=1 and untreadPost=1 and untreadNumber='') ) and isDelete=0 and sid=" . $sid,
  427. 'desc' => 'iid',
  428. 'asArray' => TRUE
  429. ) );
  430. foreach ( $list ['handleInvoice'] as $key => $value ) {
  431. $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  432. $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  433. $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  434. }
  435. }
  436. return $list;
  437. }
  438. /**
  439. * 获得所有未入账发票
  440. * @param number $invoiceTC 发票title
  441. */
  442. public function getInvoiceByUnAccount($invoiceTC='') {
  443. Doo::loadClass ( 'XDeode' );
  444. $XDeode = new XDeode ( 5 );
  445. $title="";
  446. if (!empty($invoiceTC))
  447. $title=' and (invoiceTitle like "%'.$invoiceTC.'%" or invoiceCompany like "%'.$invoiceTC.'%" )';
  448. $list = $this->find ( array (//and irid=''
  449. 'where' => "status=2 and printStatus=1 and untreadStatus=0 and ( (doPost=1 and postStatus=1) or doPost=0 ) and isDelete=0 ".$title,
  450. 'desc' => 'iid',
  451. 'asArray' => TRUE
  452. ));
  453. foreach ( $list as $key => $value ) {
  454. $list [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  455. }
  456. return $list;
  457. }
  458. /**
  459. * 获得与我有关可收款的发票,已经出票的发票
  460. * @param number $sid 开票人ID
  461. */
  462. public function getInvoiceByReceivables($sid = 0) {
  463. Doo::loadClass ( 'XDeode' );
  464. $XDeode = new XDeode ( 5 );
  465. $list ['handleInvoice'] = $this->find ( array (
  466. 'where' => "(status=2 and printStatus=1 and untreadStatus=0 ) and isDelete=0 and sid=" . $sid,
  467. 'desc' => 'iid',
  468. 'asArray' => TRUE
  469. ) );
  470. foreach ( $list ['handleInvoice'] as $key => $value ) {
  471. $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  472. $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  473. // $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  474. }
  475. return $list ['handleInvoice'];
  476. }
  477. /**
  478. * 获取需要邮寄的发票
  479. * @param integer $postStatus 0为获取需要邮寄的发票,1为获取已经邮寄的发票
  480. * @return array|array() 返回相关数据
  481. */
  482. public function getPostByInvoice($postStatus = 0) {
  483. Doo::loadClass ( 'XDeode' );
  484. $XDeode = new XDeode ( 5 );
  485. $list = $this->find ( array (
  486. 'where' => "postStatus=" . $postStatus . " and printStatus=1 and doPost=1 and status=2 and isDelete=0",
  487. 'asArray' => TRUE
  488. ) );
  489. foreach ( $list as $key => $value ) {
  490. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  491. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  492. $list [$key] ['expressCompany'] = '';
  493. $list [$key] ['expressCom'] = '';
  494. if (! empty ( $value ['expressCompany'] )) {
  495. $express = explode ( ":", $value ['expressCompany'] );
  496. $list [$key] ['expressCompany'] = $express [0];
  497. $list [$key] ['expressCom'] = $express [1];
  498. }
  499. }
  500. return $list;
  501. }
  502. /**
  503. * 根据退票状态获得相关数据,iid有值时只获得一条数据
  504. * @param number $untreadStatus 退票状态
  505. * @param number $iid 发票ID
  506. */
  507. public function getInvoiceByUntreadStatus($untreadStatus = 1, $iid = 0) {
  508. Doo::loadClass ( 'XDeode' );
  509. $XDeode = new XDeode ( 5 );
  510. if (empty ( $iid )) {
  511. $list = $this->find ( array (
  512. 'where' => " printStatus=1 and untreadStatus=" . $untreadStatus . " and status=2 ",
  513. 'asArray' => TRUE
  514. ) );
  515. if ($untreadStatus == 2) {
  516. Doo::loadModel ( 'invoiceOperationLog' );
  517. $invoiceOperationLog = new invoiceOperationLog ();
  518. }
  519. foreach ( $list as $key => $value ) {
  520. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  521. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  522. $list [$key] ['untreadCompany'] = '';
  523. $list [$key] ['untreadCom'] = '';
  524. if (! empty ( $value ['untreadCompany'] )) {
  525. $express = explode ( ":", $value ['untreadCompany'] );
  526. $list [$key] ['untreadCompany'] = $express [0];
  527. $list [$key] ['untreadCom'] = $express [1];
  528. }
  529. if ($untreadStatus == 2) {
  530. $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
  531. }
  532. }
  533. } else {
  534. $list = $this->getOne ( array (
  535. 'where' => "iid=" . $iid . " and printStatus=1 and untreadStatus=" . $untreadStatus . " and status=2",
  536. 'asArray' => TRUE
  537. ) );
  538. }
  539. return $list;
  540. }
  541. /**
  542. * 审批中获取相关数据 包括最近的一条操作记录
  543. * @param number $status.
  544. * @param number $limit.
  545. */
  546. function getInvoiceByProcessStatus($limit = 4, $desc = 'desc') {
  547. Doo::loadClass ( 'XDeode' );
  548. $XDeode = new XDeode ( 5 );
  549. $list = $this->find ( array (
  550. 'where' => " (status=1 or status=3 or status=4) and processApprovals!=''",
  551. 'limit' => $limit,
  552. $desc => 'iid',
  553. 'asArray' => TRUE
  554. ) );
  555. Doo::loadModel ( 'invoiceOperationLog' );
  556. $invoiceOperationLog = new invoiceOperationLog ();
  557. foreach ( $list as $key => $value ) {
  558. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  559. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  560. }
  561. return $list;
  562. }
  563. function getInvoiceByUntreadStatusPage($limit = 0, $con = "", $desc = 'desc') {
  564. if (empty ( $limit ) || empty ( $con ))
  565. return array ();
  566. $list = $this->find ( array (
  567. 'where' => $con,
  568. 'limit' => $limit,
  569. $desc => 'iid',
  570. 'asArray' => TRUE
  571. ) );
  572. Doo::loadClass ( 'XDeode' );
  573. $XDeode = new XDeode ( 5 );
  574. Doo::loadModel ( 'invoiceReceivables' );
  575. $invoiceReceivables = new invoiceReceivables ();
  576. Doo::loadModel ( 'invoiceOperationLog' );
  577. $invoiceOperationLog = new invoiceOperationLog ();
  578. foreach ( $list as $key => $value ) {
  579. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  580. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  581. $list [$key] ['untreadCompany'] = '';
  582. $list [$key] ['untreadCom'] = '';
  583. if (! empty ( $value ['untreadCompany'] )) {
  584. $express = explode ( ":", $value ['untreadCompany'] );
  585. $list [$key] ['untreadCompany'] = $express [0];
  586. $list [$key] ['untreadCom'] = $express [1];
  587. }
  588. $list [$key] ['irList'] = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  589. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  590. $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
  591. $list [$key] ['sumPrice'] = 0;
  592. if (! empty ( $list [$key] ['irList'] ))
  593. $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
  594. // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  595. }
  596. return $list;
  597. }
  598. /**
  599. * 加密或解密指定字符串
  600. *
  601. * @param string $string 要加密或解密的字符串
  602. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  603. * @param string $key 加解密的key
  604. * @param $expiry 超时值
  605. *
  606. */
  607. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  608. $ckey_length = 4;
  609. if (! $key) {
  610. $key = $this->INVOICEKEY;
  611. }
  612. $key = md5 ( $key );
  613. $keya = md5 ( substr ( $key, 0, 16 ) );
  614. $keyb = md5 ( substr ( $key, 16, 16 ) );
  615. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  616. $cryptkey = $keya . md5 ( $keya . $keyc );
  617. $key_length = strlen ( $cryptkey );
  618. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  619. $string_length = strlen ( $string );
  620. $result = '';
  621. $box = range ( 0, 255 );
  622. $rndkey = array ();
  623. for($i = 0; $i <= 255; $i ++) {
  624. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  625. }
  626. for($j = $i = 0; $i < 256; $i ++) {
  627. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  628. $tmp = $box [$i];
  629. $box [$i] = $box [$j];
  630. $box [$j] = $tmp;
  631. }
  632. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  633. $a = ($a + 1) % 256;
  634. $j = ($j + $box [$a]) % 256;
  635. $tmp = $box [$a];
  636. $box [$a] = $box [$j];
  637. $box [$j] = $tmp;
  638. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  639. }
  640. if ($operation == 'DECODE') {
  641. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  642. return substr ( $result, 26 );
  643. } else {
  644. return '';
  645. }
  646. } else {
  647. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  648. }
  649. }
  650. }
  651. ?>