invoice.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  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. if (! empty ( $detail ['expressCompany'] )) {
  358. $express = explode ( ":", $detail ['expressCompany'] );
  359. $detail ['expressCompany'] = $express [0];
  360. $detail ['expressCom'] = $express [1];
  361. }
  362. $detail ['iidKeyXD'] = $this->authcode ( $detail ['iid'], '' );
  363. return $detail;
  364. }
  365. /**
  366. * 统计培训班开票
  367. */
  368. function sumOfinvoiceTrain($itidSql) {
  369. $sql = 'select sum(invoicePrice) as invoicePrice ,trainId
  370. from ' . $this->_table . '
  371. where trainId in ('.$itidSql.') and status=2 and printStatus=1 and (untreadStatus =0 or untreadStatus=3)
  372. GROUP BY trainId';
  373. $query = Doo::db ()->query ( $sql );
  374. return $result = $query->fetchAll ();
  375. }
  376. function sumOfInvoiceRecelvablesTrain($itidSql){
  377. $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
  378. from ' . $this->_table . ' as a left join CLD_invoiceReceivables as b on find_in_set(a.irid,b.irid)
  379. where a.trainId in ('.$itidSql.') and a.status=2 and a.printStatus=1 and (a.untreadStatus =0 or a.untreadStatus=3) and a.irid!=""
  380. GROUP BY a.trainId';
  381. $query = Doo::db ()->query ( $sql );
  382. return $result = $query->fetchAll ();
  383. }
  384. /**
  385. * 根据仓库ID获得发票
  386. * @param string $Istoreid
  387. * @return unknown
  388. */
  389. public function getInvoiceByIstoreid($Istoreid = "", $select = "") {
  390. if (empty ( $Istoreid ))
  391. return array ();
  392. $condition = array (
  393. 'where' => "isid in ( " . $Istoreid . ")",
  394. 'asArray' => TRUE
  395. );
  396. if (! empty ( $select ))
  397. $condition += array (
  398. 'select' => $select
  399. );
  400. $detail = $this->find ( $condition );
  401. return $detail;
  402. }
  403. /**
  404. * 获取单个可以打印的发票数据
  405. * @param number $iid 发票id
  406. * @param number $select 需要获取的字段,为空获取全部数据
  407. * @return array|array() 返回发票数据
  408. */
  409. public function getInvoiceByPrint($iid = 0, $select = "") {
  410. $condition = array (
  411. 'where' => "iid= '" . $iid . "' and status=2 and untreadStatus=0 ",
  412. 'asArray' => TRUE
  413. );
  414. if (! empty ( $select ))
  415. $condition += array (
  416. 'select' => $select
  417. );
  418. $detail = array ();
  419. if (! empty ( $iid ) && is_numeric ( $iid ))
  420. $detail = $this->getOne ( $condition );
  421. return $detail;
  422. }
  423. /**
  424. * 添加一个发票并进入审批状态
  425. * @param array $item 发票相关数据
  426. * @return number 返回发票ID
  427. */
  428. public function addInvoice($item = array()) {
  429. $lid = 0;
  430. if (is_array ( $item ) && ! empty ( $item )) {
  431. foreach ( $item as $key => $value ) {
  432. $this->$key = $value;
  433. }
  434. $lid = $this->insert ();
  435. }
  436. return $lid;
  437. }
  438. /**
  439. * 根据参数字段更新相应字段(主键ID必须传)
  440. * @param array $item 相关需要更新的字段信息
  441. * @return number 返回发票ID
  442. */
  443. public function setInvoiceByCondition($item = array()) {
  444. $lid = 0;
  445. if (is_array ( $item ) && ! empty ( $item )) {
  446. foreach ( $item as $key => $value ) {
  447. $this->$key = $value;
  448. }
  449. $lid = $this->update ();
  450. }
  451. return $lid;
  452. }
  453. /**
  454. * 根据参数字段批量更新相应字段(主键ID必须传)
  455. * @param array $item 相关需要更新的字段信息
  456. * @return number 返回发票ID
  457. */
  458. public function BatchInvoiceByCondition($item = array(), $iid = "") {
  459. $lid = 0;
  460. if (is_array ( $item ) && ! empty ( $item )) {
  461. foreach ( $item as $key => $value ) {
  462. $this->$key = $value;
  463. }
  464. if (! empty ( $iid )) {
  465. $condition = array (
  466. 'where' => "iid in (" . $iid . ")",
  467. 'asArray' => TRUE
  468. );
  469. $this->update ( $condition );
  470. } else
  471. $lid = $this->update ();
  472. }
  473. return $lid;
  474. }
  475. /**
  476. * 根据管理组和发票当前状态获得打印发票数据;其中当iid为空时获取所有发票数据,反之获取1条数据
  477. * @param number $sid 管理组人员ID
  478. * @param number $status 状态 为0时获取可以打印数据,为1时获取已经完成打印数据
  479. * @param number $iid 发票ID
  480. * @return array|array() 返回所有发票数据,当iid有值时返回一条数据
  481. */
  482. public function getPrintInvoiceByManage($sid = 0, $status = 0, $iid = 0) {
  483. $list = array ();
  484. if (! empty ( $sid ) && empty ( $iid ))
  485. $list = $this->find ( array (
  486. 'where' => "status=2 and printStatus=" . $status . " and untreadStatus=0 and moldManage like '%[\"" . $sid . "\",%'",
  487. 'desc' => 'iid',
  488. 'asArray' => TRUE
  489. ) );
  490. elseif (! empty ( $sid ) && ! empty ( $iid ))
  491. $list = $this->getOne ( array (
  492. 'where' => "status=2 and printStatus=" . $status . " and untreadStatus=0 and moldManage like '%[\"" . $sid . "\",%' and iid=" . $iid,
  493. 'asArray' => TRUE
  494. ) );
  495. return $list;
  496. }
  497. /**
  498. * 获得与我相关的发票数据,其中包含 处理中,待处理,最旧入账等数据;当iid有值时获取一条关于sid的发票
  499. * @param number $sid 用户ID
  500. * @param number $iid 发票ID
  501. * @return array|array()
  502. */
  503. public function getMyInvoice($sid = 0, $iid = 0) {
  504. Doo::loadModel ( 'invoiceOperationLog' );
  505. $invoiceOperationLog = new invoiceOperationLog ();
  506. Doo::loadClass ( 'XDeode' );
  507. $XDeode = new XDeode ( 5 );
  508. $list = array ();
  509. if (! empty ( $iid )) {
  510. $list = $this->getOne ( array (
  511. 'where' => " sid=" . $sid . " and iid=" . $iid,
  512. 'asArray' => TRUE
  513. ) );
  514. } elseif (! empty ( $sid ) && empty ( $iid )) {
  515. $list ['pendingInvoice'] = array ();
  516. $list ['handleInvoice'] = array ();
  517. $list ['pendingInvoice'] = $this->find ( array ( // 加入邮件中也为 处理中 已退票
  518. 'where' => "((status=1 and untreadStatus=0) or (status=2 and printStatus=0 and untreadStatus=0) or
  519. ( status=2 and printStatus=1 and untreadStatus=1 and untreadPost=0)
  520. or (postStatus=0 and doPost=1 and status=2 and untreadStatus=0) ) and isDelete=0 and sid=" . $sid,
  521. 'desc' => 'iid',
  522. 'asArray' => TRUE
  523. ) );
  524. foreach ( $list ['pendingInvoice'] as $key => $value ) {
  525. $list ['pendingInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  526. $list ['pendingInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  527. }
  528. $list ['handleInvoice'] = $this->find ( array (
  529. // 需求变更 -去除出票状态的数据 or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  530. // 新加入退票中 需要邮寄的发票
  531. 'where' => "(status=3 or status=4 or (status=2 and untreadStatus=2 ) or ( status=2 and untreadStatus=1 ) ) and isDelete=0 and sid=" . $sid,
  532. 'desc' => 'iid',
  533. 'asArray' => TRUE
  534. ) );
  535. foreach ( $list ['handleInvoice'] as $key => $value ) {
  536. $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  537. $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  538. $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  539. }
  540. }
  541. return $list;
  542. }
  543. /**
  544. * 获得所有未入账发票
  545. * @param number $invoiceTC 发票title
  546. */
  547. public function getInvoiceByUnAccount($invoiceTC = '', $iridExist = false) {
  548. Doo::loadClass ( 'XDeode' );
  549. $XDeode = new XDeode ( 5 );
  550. $title = "";
  551. if (! empty ( $invoiceTC ))
  552. $title = ' and (invoiceTitle like "%' . $invoiceTC . '%" or invoiceCompany like "%' . $invoiceTC . '%" )';
  553. $iridString = ' and irid="" ';
  554. if ($iridExist)
  555. $iridString = ' and irid!="" ';
  556. $list = $this->find ( array ( //
  557. 'where' => "status=2 and printStatus=1 " . $iridString . " and untreadStatus=0 and ( (doPost=1 and postStatus=1) or doPost=0 ) and isDelete=0 " . $title,
  558. 'desc' => 'iid',
  559. 'limit' => 5,
  560. 'asArray' => TRUE
  561. ) );
  562. foreach ( $list as $key => $value ) {
  563. $list [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  564. }
  565. return $list;
  566. }
  567. /**
  568. * 获得与我有关可收款的发票,已经出票的发票
  569. * @param number $sid 开票人ID
  570. */
  571. public function getInvoiceByReceivables($sid = 0) {
  572. Doo::loadClass ( 'XDeode' );
  573. $XDeode = new XDeode ( 5 );
  574. $list ['handleInvoice'] = $this->find ( array (
  575. 'where' => "(status=2 and printStatus=1 and untreadStatus=0 ) and isDelete=0 and sid=" . $sid,
  576. 'desc' => 'iid',
  577. 'asArray' => TRUE
  578. ) );
  579. foreach ( $list ['handleInvoice'] as $key => $value ) {
  580. $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  581. $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  582. // $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  583. }
  584. return $list ['handleInvoice'];
  585. }
  586. /**
  587. * 获取需要邮寄的发票
  588. * @param integer $postStatus 0为获取需要邮寄的发票,1为获取已经邮寄的发票
  589. * @return array|array() 返回相关数据
  590. */
  591. public function getPostByInvoice($postStatus = 0) {
  592. Doo::loadClass ( 'XDeode' );
  593. $XDeode = new XDeode ( 5 );
  594. $list = $this->find ( array ( // and untreadStatus=0
  595. 'where' => "postStatus=" . $postStatus . " and printStatus=1 and doPost=1 and status=2 and isDelete=0",
  596. 'limit' => 7,
  597. 'asArray' => TRUE
  598. ) );
  599. foreach ( $list as $key => $value ) {
  600. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  601. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  602. $list [$key] ['expressCompany'] = '';
  603. $list [$key] ['expressCom'] = '';
  604. if (! empty ( $value ['expressCompany'] )) {
  605. $express = explode ( ":", $value ['expressCompany'] );
  606. $list [$key] ['expressCompany'] = $express [0];
  607. $list [$key] ['expressCom'] = $express [1];
  608. }
  609. }
  610. return $list;
  611. }
  612. /**
  613. * 根据退票状态获得相关数据,iid有值时只获得一条数据
  614. * @param number $untreadStatus 退票状态
  615. * @param number $iid 发票ID
  616. */
  617. public function getInvoiceByUntreadStatus($untreadStatus = 1, $iid = 0) {
  618. Doo::loadClass ( 'XDeode' );
  619. $XDeode = new XDeode ( 5 );
  620. if (empty ( $iid )) {
  621. $list = $this->find ( array ( // printStatus=1 and
  622. 'where' => " untreadStatus=" . $untreadStatus . " and status=2 ",
  623. 'asArray' => TRUE
  624. ) );
  625. if ($untreadStatus == 2) {
  626. Doo::loadModel ( 'invoiceOperationLog' );
  627. $invoiceOperationLog = new invoiceOperationLog ();
  628. }
  629. foreach ( $list as $key => $value ) {
  630. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  631. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  632. $list [$key] ['untreadCompany'] = '';
  633. $list [$key] ['untreadCom'] = '';
  634. if (! empty ( $value ['untreadCompany'] )) {
  635. $express = explode ( ":", $value ['untreadCompany'] );
  636. $list [$key] ['untreadCompany'] = $express [0];
  637. $list [$key] ['untreadCom'] = $express [1];
  638. }
  639. if ($untreadStatus == 2) {
  640. $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
  641. }
  642. $list [$key] ['lossDetail'] = array ();
  643. if ($value ['lossIid'] != 0) {
  644. $detail = $this->getOne ( array (
  645. 'where' => "iid=" . $value ['lossIid'],
  646. 'asArray' => TRUE
  647. ) );
  648. $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
  649. $list [$key] ['lossDetail'] = $detail;
  650. }
  651. }
  652. } else {
  653. $list = $this->getOne ( array (
  654. 'where' => "iid=" . $iid . " and printStatus=1 and untreadStatus=" . $untreadStatus . " and status=2",
  655. 'asArray' => TRUE
  656. ) );
  657. }
  658. return $list;
  659. }
  660. /**
  661. * 审批中获取相关数据 包括最近的一条操作记录
  662. * @param number $status.
  663. * @param number $limit.
  664. */
  665. function getInvoiceByProcessStatus($limit = 4, $desc = 'desc') {
  666. Doo::loadClass ( 'XDeode' );
  667. $XDeode = new XDeode ( 5 );
  668. $list = $this->find ( array (
  669. 'where' => " (status=1 or status=2 or status=3 or status=4) and processApprovals!=''",
  670. 'limit' => $limit,
  671. $desc => 'iid',
  672. 'asArray' => TRUE
  673. ) );
  674. Doo::loadModel ( 'invoiceOperationLog' );
  675. $invoiceOperationLog = new invoiceOperationLog ();
  676. foreach ( $list as $key => $value ) {
  677. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  678. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 2 );
  679. }
  680. return $list;
  681. }
  682. function getInvoiceByUntreadStatusPage($limit = 0, $con = "", $desc = 'desc',$olStatus="desc") {
  683. if (empty ( $limit ) || empty ( $con ))
  684. return array ();
  685. $list = $this->find ( array (
  686. 'where' => $con,
  687. 'limit' => $limit,
  688. $desc => 'iid',
  689. 'asArray' => TRUE
  690. ) );
  691. Doo::loadClass ( 'XDeode' );
  692. $XDeode = new XDeode ( 5 );
  693. Doo::loadModel ( 'invoiceReceivables' );
  694. $invoiceReceivables = new invoiceReceivables ();
  695. Doo::loadModel ( 'invoiceOperationLog' );
  696. $invoiceOperationLog = new invoiceOperationLog ();
  697. foreach ( $list as $key => $value ) {
  698. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  699. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  700. $list [$key] ['untreadCompany'] = '';
  701. $list [$key] ['untreadCom'] = '';
  702. if (! empty ( $value ['untreadCompany'] )) {
  703. $express = explode ( ":", $value ['untreadCompany'] );
  704. $list [$key] ['untreadCompany'] = $express [0];
  705. $list [$key] ['untreadCom'] = $express [1];
  706. }
  707. $list [$key] ['irList'] = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  708. if ($olStatus=='desc')
  709. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  710. else
  711. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], $olStatus );
  712. $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
  713. //print_r($list [$key] ['OperationLog']);
  714. $list [$key] ['sumPrice'] = 0;
  715. if (! empty ( $list [$key] ['irList'] ))
  716. $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
  717. // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  718. $list [$key] ['lossDetail'] = array ();
  719. if ($value ['lossIid'] != 0) {
  720. $detail = $this->getOne ( array (
  721. 'where' => "iid=" . $value ['lossIid'],
  722. 'asArray' => TRUE
  723. ) );
  724. $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
  725. $list [$key] ['lossDetail'] = $detail;
  726. }
  727. $lossDate = strtotime ( "+1 month", strtotime ( $list [$key] ['OperationLog'] ['date'] ) );
  728. $nowDate = strtotime ( 'now' );
  729. $list [$key] ['lossShow'] = false;
  730. if ($lossDate < $nowDate)
  731. $list [$key] ['lossShow'] = true;
  732. }
  733. return $list;
  734. }
  735. /**
  736. * 加密或解密指定字符串
  737. *
  738. * @param string $string 要加密或解密的字符串
  739. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  740. * @param string $key 加解密的key
  741. * @param $expiry 超时值
  742. *
  743. */
  744. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  745. $ckey_length = 4;
  746. if (! $key) {
  747. $key = $this->INVOICEKEY;
  748. }
  749. $key = md5 ( $key );
  750. $keya = md5 ( substr ( $key, 0, 16 ) );
  751. $keyb = md5 ( substr ( $key, 16, 16 ) );
  752. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  753. $cryptkey = $keya . md5 ( $keya . $keyc );
  754. $key_length = strlen ( $cryptkey );
  755. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  756. $string_length = strlen ( $string );
  757. $result = '';
  758. $box = range ( 0, 255 );
  759. $rndkey = array ();
  760. for($i = 0; $i <= 255; $i ++) {
  761. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  762. }
  763. for($j = $i = 0; $i < 256; $i ++) {
  764. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  765. $tmp = $box [$i];
  766. $box [$i] = $box [$j];
  767. $box [$j] = $tmp;
  768. }
  769. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  770. $a = ($a + 1) % 256;
  771. $j = ($j + $box [$a]) % 256;
  772. $tmp = $box [$a];
  773. $box [$a] = $box [$j];
  774. $box [$j] = $tmp;
  775. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  776. }
  777. if ($operation == 'DECODE') {
  778. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  779. return substr ( $result, 26 );
  780. } else {
  781. return '';
  782. }
  783. } else {
  784. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  785. }
  786. }
  787. }
  788. ?>