invoice.php 25 KB

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