invoice.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  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. public $approvalTime;
  183. /**
  184. *
  185. * @var date $updateTime 更新时间
  186. */
  187. public $updateTime;
  188. /**
  189. *
  190. * @var date $printTime 打印时间
  191. */
  192. public $printTime;
  193. public $postTime;
  194. public $settlementType;
  195. public $accountingTime;
  196. public $parentUntreadIid;
  197. public $inheritIid;
  198. public $_table = 'CLD_invoice';
  199. public $_primarykey = 'iid';
  200. public $_fields = array (
  201. 'iid',
  202. 'isid',
  203. 'trainId',
  204. 'ipSource',
  205. 'lossIid',
  206. 'invoiceManage',
  207. 'pendingApprovals',
  208. 'processApprovals',
  209. 'invoiceSerial',
  210. 'status',
  211. 'printStatus',
  212. 'postStatus',
  213. 'untreadStatus',
  214. 'invoiceQuantity',
  215. 'invoiceUnitPrice',
  216. 'invoicePrice',
  217. 'moldManage',
  218. 'cid',
  219. 'categoryName',
  220. 'irid',
  221. 'remark',
  222. 'invoiceElement',
  223. 'invoiceType',
  224. 'invoiceTitle',
  225. 'invoiceCompany',
  226. 'invoiceNo',
  227. 'TIN',
  228. 'address',
  229. 'phone',
  230. 'bank',
  231. 'bankAccount',
  232. 'doPost',
  233. 'recipients',
  234. 'recipientsPhone',
  235. 'recipientsAddress',
  236. 'mailItems',
  237. 'mailItemsJson',
  238. 'expressCompany',
  239. 'expressNumber',
  240. 'actualItems',
  241. 'untreadReason',
  242. 'untreadPost',
  243. 'untreadCompany',
  244. 'untreadNumber',
  245. 'untreadItems',
  246. 'poster',
  247. 'sid',
  248. 'userName',
  249. 'printer',
  250. 'date',
  251. 'isDelete',
  252. 'approvalTime',
  253. 'updateTime',
  254. 'printTime',
  255. 'postTime',
  256. 'bindTime',
  257. 'settlementType',
  258. 'accountingTime',
  259. 'parentUntreadIid',
  260. 'inheritIid'
  261. );
  262. /**
  263. * 获得培训班结算金额总和
  264. * @param iids $
  265. * @return int
  266. */
  267. function getInvoicePriceByIids($iids=''){
  268. if (empty($iids)){
  269. return 0;
  270. }
  271. $sum = $this->getOne ( array (
  272. 'select' => 'sum(invoicePrice) as price',
  273. 'where' => " trainId in (" .$iids.")",
  274. 'asArray' => TRUE
  275. ) );
  276. return $sum['price'];
  277. }
  278. /**
  279. * 根据发票ID获取一条发票数据
  280. * @param number $iid 发票ID
  281. * @param number $select 需要获取的字段,为空获取全部数据
  282. * @return array|array() 返回发票数据
  283. */
  284. public function getInvoiceByIid($iid = 0, $select = "") {
  285. if (! is_numeric ( $iid ))
  286. $iid = $this->authcode ( $iid );
  287. $condition = array (
  288. 'where' => "iid=" . $iid,
  289. 'asArray' => TRUE
  290. );
  291. if (! empty ( $select ))
  292. $condition += array (
  293. 'select' => $select
  294. );
  295. $Detail = array ();
  296. if (is_numeric ( $iid ) && ! empty ( $iid ))
  297. $Detail = $this->getOne ( $condition );
  298. if (empty ( $Detail ))
  299. return $Detail;
  300. if (isset ( $Detail ['expressCompany'] ) && ! empty ( $Detail ['expressCompany'] )) {
  301. $express = explode ( ":", $Detail ['expressCompany'] );
  302. $Detail ['expressCompany'] = $express [0];
  303. $Detail ['expressCom'] = $express [1];
  304. } else {
  305. $Detail ['expressCompany'] = '';
  306. $Detail ['expressCom'] = '';
  307. }
  308. Doo::loadClass ( 'XDeode' );
  309. $XDeode = new XDeode ( 5 );
  310. $Detail ['iidKeyUrl'] = $XDeode->encode ( $Detail ['iid'] );
  311. $Detail ['iidKey'] = $this->authcode ( $Detail ['iid'], '' );
  312. Doo::loadModel ( 'L_category' );
  313. $lCategory = new L_category ();
  314. $Detail ['category'] = $lCategory->getCategory ();
  315. return $Detail;
  316. }
  317. /**
  318. * 根据培训班ID获得发票
  319. */
  320. function getInvoicePrintedByItid($trainId = 0) {
  321. $sql = 'select a.*,b.RIstatus as RIstatus
  322. from ' . $this->_table . ' as a left join CLD_RIExtend as b on (a.iid=b.iid)
  323. where a.trainId = ' . $trainId . ' and a.status=2 and a.printStatus=1 and (a.untreadStatus=0 or a.untreadStatus=3) ORDER BY a.iid ASC';
  324. $query = Doo::db ()->query ( $sql );
  325. $result = $query->fetchAll ();
  326. Doo::loadClass ( 'XDeode' );
  327. $XDeode = new XDeode ( 5 );
  328. Doo::loadModel ( 'invoiceReceivables' );
  329. $invoiceReceivables = new invoiceReceivables ();
  330. $isFinance=false;
  331. foreach ($result as $key=>$value){
  332. $result [$key] ['irDetail'] =$invoiceReceivables->getInvoiceReceivablesByIridList($value ['irid']);
  333. foreach ($result [$key] ['irDetail'] as $k=>$v){
  334. if($v['receivablesBank']=='财务录入'){
  335. $isFinance=true;
  336. break;
  337. }
  338. }
  339. $result [$key] ['isFinance'] =$isFinance;
  340. $result [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  341. }
  342. return $result;
  343. // $condition = array (
  344. // 'where' => "trainId = " . $trainId . " and status=2 and printStatus=1 and (untreadStatus=0 or untreadStatus=3)",
  345. // 'asArray' => TRUE
  346. // );
  347. // $detail = $this->find ( $condition );
  348. // return $detail;
  349. }
  350. //办事处收款 有问题--已经退票的发票,还会统计到办事处收款中BUG--点击办事处已收款后,在退票就会出现统计错误
  351. function sumOfInvoiceByItid($itidSql=0){
  352. $sql = 'select sum(a.invoicePrice) as invoicePrice ,a.trainId as trainId,a.iid
  353. from CLD_RIExtend as b left join ' . $this->_table . ' as a on (a.iid=b.iid)
  354. where (a.trainId in (' . $itidSql . ') and a.status=2 and a.printStatus=1 and a.untreadStatus=3) or b.RIstatus=1
  355. GROUP BY a.trainId';
  356. //echo $sql;
  357. $query = Doo::db ()->query ( $sql );
  358. return $result = $query->fetchAll ();
  359. }
  360. /**
  361. * 根据多个iid获得多个发票
  362. * @param number $iid
  363. */
  364. function getInvoiceInIid($iid = 0, $select = '') {
  365. if (empty ( $iid ))
  366. die ( 'illegal request' );
  367. $condition = array (
  368. 'where' => "iid in ( " . $iid . ")",
  369. 'asArray' => TRUE
  370. );
  371. if (! empty ( $select ))
  372. $condition += array (
  373. 'select' => $select
  374. );
  375. $list = $this->find ( $condition );
  376. Doo::loadClass ( 'XDeode' );
  377. $XDeode = new XDeode ( 5 );
  378. foreach ( $list as $key => $value ) {
  379. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  380. }
  381. return $list;
  382. }
  383. function setInvoiceLoss($iid = "") {
  384. if (empty ( $iid ))
  385. return 0;
  386. $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`)
  387. 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;
  388. $query = Doo::db ()->query ( $sql );
  389. return Doo::db ()->lastInsertId ();
  390. }
  391. function getInvoiceByInvoiceNo($invoiceNo = '') {
  392. if (empty ( $invoiceNo ))
  393. return array ();
  394. $detail = $this->getOne ( array (
  395. 'where' => "invoiceNo= '" . $invoiceNo . "'",
  396. 'asArray' => TRUE
  397. ) );
  398. return $detail;
  399. }
  400. /**
  401. * 根据标题或者开票单位获得相关信息 - 准确查询
  402. * @param string $title 查询条件
  403. * @param string $query 默认模糊查询
  404. */
  405. public function getInvoiceByTitle($title = "", $query = "FUZZY", $cond = '', $fkq = false) {
  406. $detail = array ();
  407. if (! empty ( $title )) {
  408. $condition = array (
  409. 'asArray' => TRUE
  410. );
  411. if ($query == $this->FUZZY)
  412. $condition += array (
  413. 'where' => " (invoiceTitle like '%" . $title . "%' or invoiceCompany like '%" . $title . "%') " . $cond
  414. );
  415. else
  416. $condition += array (
  417. 'where' => "(invoiceTitle = '" . $title . "' or invoiceCompany= '" . $title . "') " . $cond
  418. );
  419. Doo::loadClass ( 'XDeode' );
  420. $XDeode = new XDeode ( 5 );
  421. if ($fkq) {
  422. $detail = $this->find ( $condition );
  423. foreach ( $detail as $key => $value ) {
  424. $detail [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  425. $detail [$key] ['iidKeyXD'] = $XDeode->encode ( $value ['iid'] );
  426. }
  427. } else {
  428. $detail = $this->getOne ( $condition );
  429. if (! empty ( $detail )) {
  430. $detail ['iidKey'] = $this->authcode ( $detail ['iid'], '' );
  431. $detail ['iidKeyXD'] = $XDeode->encode ( $detail ['iid'] );
  432. }
  433. }
  434. }
  435. return $detail;
  436. }
  437. public function getInvoiceByIsid($iid = "", $sid = 0) {
  438. if (empty ( $iid ) || empty ( $sid ))
  439. return array ();
  440. Doo::loadClass ( 'XDeode' );
  441. $XDeode = new XDeode ( 5 );
  442. $iid = $XDeode->decode ( $iid );
  443. if (! is_numeric ( $iid ))
  444. return array ();
  445. $detail = $this->getOne ( array (
  446. 'where' => "iid= '" . $iid . "'", // and sid=".$sid,
  447. 'asArray' => TRUE
  448. ) );
  449. $detail ['expressCompany'] = '';
  450. $detail ['expressCom'] = '';
  451. $detail ['invoiceTraining'] = array ();
  452. if (! empty ( $detail ['expressCompany'] )) {
  453. $express = explode ( ":", $detail ['expressCompany'] );
  454. $detail ['expressCompany'] = $express [0];
  455. $detail ['expressCom'] = $express [1];
  456. }
  457. // 培训班
  458. if ($detail ['settlementType'] == 1) {
  459. Doo::loadModel ( 'invoiceTraining' );
  460. $invoiceTraining = new invoiceTraining ();
  461. $detail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $detail ['trainId'] );
  462. }
  463. $detail ['iidKeyXD'] = $this->authcode ( $detail ['iid'], '' );
  464. return $detail;
  465. }
  466. /**
  467. * 统计培训班开票
  468. */
  469. function sumOfinvoiceTrain($itidSql) {
  470. // $sql = 'select sum(b.invoicePrice) as invoicePrice ,b.trainId as trainId
  471. // from CLD_invoiceStore as a left join ' . $this->_table . ' as b on (a.iid=b.iid)
  472. // where b.trainId in (' . $itidSql . ') and b.status=2 and b.printStatus=1 and (b.untreadStatus =0 or b.untreadStatus=3) and b.isDelete=0
  473. // GROUP BY b.trainId';
  474. $sql = 'select sum(b.invoicePrice) as invoicePrice ,b.trainId as trainId
  475. from ' . $this->_table . ' as b
  476. where b.trainId in (' . $itidSql . ') and b.status=2 and b.printStatus=1 and (b.untreadStatus =0 or b.untreadStatus=3) and b.isDelete=0
  477. GROUP BY b.trainId';
  478. $query = Doo::db ()->query ( $sql );
  479. return $result = $query->fetchAll ();
  480. }
  481. /**
  482. * 公司收款汇总
  483. * @param unknown $itidSql
  484. */
  485. function sumOfInvoiceRecelvablesCompany($itidSql) {
  486. $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
  487. from ' . $this->_table . ' as a left join CLD_invoiceReceivables as b on (a.iid=b.iid)
  488. where a.trainId in (' . $itidSql . ') and b.receivablesBank!="财务录入" and a.status=2 and a.printStatus=1 and ( a.untreadStatus=3) and a.irid!=""
  489. GROUP BY a.trainId';
  490. $query = Doo::db ()->query ( $sql );
  491. return $result = $query->fetchAll ();
  492. }
  493. //
  494. function sumOfInvoiceRecelvablesTrain($itidSql) {
  495. // $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
  496. // from ' . $this->_table . ' as a left join CLD_invoiceReceivables as b on find_in_set(a.irid,b.irid)
  497. // where a.trainId in (' . $itidSql . ') and a.status=2 and a.printStatus=1 and (a.untreadStatus =0 or a.untreadStatus=3) and a.irid!=""
  498. // GROUP BY a.trainId';
  499. $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
  500. from ' . $this->_table . ' as a left join CLD_invoiceReceivables as b on (a.iid=b.iid)
  501. where a.trainId in (' . $itidSql . ') and a.status=2 and a.printStatus=1 and (a.untreadStatus =0 or a.untreadStatus=3) and a.irid!=""
  502. GROUP BY a.trainId';
  503. $query = Doo::db ()->query ( $sql );
  504. return $result = $query->fetchAll ();
  505. }
  506. // 获得培训班发票
  507. function getInvoiceByTrainingCount($itid = 0) {
  508. if (empty ( $itid ))
  509. return 0;
  510. $sql = 'select count(*) as count from CLD_invoiceStore as a left join ' . $this->_table . ' as b on (a.iid=b.iid)
  511. where a.trainId= ' . $itid . ' and b.status!=4 and (b.untreadStatus is null or b.untreadStatus!=2) and (b.isDelete is null or b.isDelete=0 )';
  512. //echo $sql;
  513. //echo $sql;
  514. $query = Doo::db ()->query ( $sql );
  515. $result = $query->fetchAll ();
  516. return $result [0] ['count'];
  517. // $detail = $this->count ( array (
  518. // 'where' => "trainId= '" . $itid . "' and untreadStatus!=2 and isDelete=0", // and sid=".$sid,
  519. // 'asArray' => TRUE
  520. // ) );
  521. // return $detail;
  522. }
  523. /**
  524. * 根据仓库ID获得发票
  525. * @param string $Istoreid
  526. * @return unknown
  527. */
  528. public function getInvoiceByIstoreid($Istoreid = "", $select = "") {
  529. if (empty ( $Istoreid ))
  530. return array ();
  531. $condition = array (
  532. 'where' => "isid in ( " . $Istoreid . ")",
  533. 'asArray' => TRUE
  534. );
  535. if (! empty ( $select ))
  536. $condition += array (
  537. 'select' => $select
  538. );
  539. $detail = $this->find ( $condition );
  540. return $detail;
  541. }
  542. /**
  543. * 获取单个可以打印的发票数据
  544. * @param number $iid 发票id
  545. * @param number $select 需要获取的字段,为空获取全部数据
  546. * @return array|array() 返回发票数据
  547. */
  548. public function getInvoiceByPrint($iid = 0, $select = "") {
  549. $condition = array (
  550. 'where' => "iid= '" . $iid . "' and status=2 and untreadStatus=0 ",
  551. 'asArray' => TRUE
  552. );
  553. if (! empty ( $select ))
  554. $condition += array (
  555. 'select' => $select
  556. );
  557. $detail = array ();
  558. if (! empty ( $iid ) && is_numeric ( $iid ))
  559. $detail = $this->getOne ( $condition );
  560. return $detail;
  561. }
  562. /**
  563. * 添加一个发票并进入审批状态
  564. * @param array $item 发票相关数据
  565. * @return number 返回发票ID
  566. */
  567. public function addInvoice($item = array()) {
  568. $lid = 0;
  569. if (is_array ( $item ) && ! empty ( $item )) {
  570. foreach ( $item as $key => $value ) {
  571. $this->$key = $value;
  572. }
  573. $lid = $this->insert ();
  574. }
  575. return $lid;
  576. }
  577. /**
  578. * 根据参数字段更新相应字段(主键ID必须传)
  579. * @param array $item 相关需要更新的字段信息
  580. * @return number 返回发票ID
  581. */
  582. public function setInvoiceByCondition($item = array()) {
  583. $lid = 0;
  584. if (is_array ( $item ) && ! empty ( $item )) {
  585. foreach ( $item as $key => $value ) {
  586. $this->$key = $value;
  587. }
  588. $lid = $this->update ();
  589. }
  590. return $lid;
  591. }
  592. /**
  593. * 根据参数字段批量更新相应字段(主键ID必须传)
  594. * @param array $item 相关需要更新的字段信息
  595. * @return number 返回发票ID
  596. */
  597. public function BatchInvoiceByCondition($item = array(), $iid = "") {
  598. $lid = 0;
  599. if (is_array ( $item ) && ! empty ( $item )) {
  600. foreach ( $item as $key => $value ) {
  601. $this->$key = $value;
  602. }
  603. if (! empty ( $iid )) {
  604. $condition = array (
  605. 'where' => "iid in (" . $iid . ")",
  606. 'asArray' => TRUE
  607. );
  608. $this->update ( $condition );
  609. } else
  610. $lid = $this->update ();
  611. }
  612. return $lid;
  613. }
  614. /**
  615. * 批量更新
  616. * @param string $isid
  617. * @return number
  618. */
  619. function UpdateBatchInvoice($sql = "") {
  620. if (empty ( $sql ))
  621. return 0;
  622. $query = Doo::db ()->query ( $sql );
  623. }
  624. /**
  625. * 根据管理组和发票当前状态获得打印发票数据;其中当iid为空时获取所有发票数据,反之获取1条数据
  626. * @param number $sid 管理组人员ID
  627. * @param number $status 状态 为0时获取可以打印数据,为1时获取已经完成打印数据
  628. * @param number $iid 发票ID
  629. * @return array|array() 返回所有发票数据,当iid有值时返回一条数据
  630. */
  631. public function getPrintInvoiceByManage($sid = 0, $status = 0, $iid = 0) {
  632. $list = array ();
  633. if (! empty ( $sid ) && empty ( $iid ))
  634. $list = $this->find ( array (
  635. 'where' => "status=2 and printStatus=" . $status . " and untreadStatus=0 and moldManage like '%[\"" . $sid . "\",%'",
  636. 'desc' => 'approvalTime',
  637. 'limit' => 10,
  638. 'asArray' => TRUE
  639. ) );
  640. elseif (! empty ( $sid ) && ! empty ( $iid ))
  641. $list = $this->getOne ( array (
  642. 'where' => "status=2 and printStatus=" . $status . " and untreadStatus=0 and moldManage like '%[\"" . $sid . "\",%' and iid=" . $iid,
  643. 'asArray' => TRUE
  644. ) );
  645. return $list;
  646. }
  647. /**
  648. * 获得与我相关的发票数据,其中包含 处理中,待处理,最旧入账等数据;当iid有值时获取一条关于sid的发票
  649. * @param number $sid 用户ID
  650. * @param number $iid 发票ID
  651. * @return array|array()
  652. */
  653. public function getMyInvoice($sid = 0, $iid = 0) {
  654. Doo::loadModel ( 'invoiceOperationLog' );
  655. $invoiceOperationLog = new invoiceOperationLog ();
  656. Doo::loadClass ( 'XDeode' );
  657. $XDeode = new XDeode ( 5 );
  658. $list = array ();
  659. if (! empty ( $iid )) {
  660. $list = $this->getOne ( array (
  661. 'where' => " sid=" . $sid . " and iid=" . $iid,
  662. 'asArray' => TRUE
  663. ) );
  664. } elseif (! empty ( $sid ) && empty ( $iid )) {
  665. $list ['pendingInvoice'] = array ();
  666. $list ['handleInvoice'] = array ();
  667. $list ['pendingInvoice'] = $this->find ( array ( // 加入邮件中也为 处理中 已退票
  668. 'where' => "((status=1 and untreadStatus=0) or (status=2 and printStatus=0 and untreadStatus=0) or
  669. ( status=2 and printStatus=1 and untreadStatus=1 and untreadPost=0)
  670. or (postStatus=0 and doPost=1 and status=2 and untreadStatus=0) ) and isDelete=0 and sid=" . $sid,
  671. 'desc' => 'iid',
  672. 'asArray' => TRUE
  673. ) );
  674. foreach ( $list ['pendingInvoice'] as $key => $value ) {
  675. $list ['pendingInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  676. $list ['pendingInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  677. }
  678. $list ['handleInvoice'] = $this->find ( array (
  679. // 需求变更 -去除出票状态的数据 or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  680. // 新加入退票中 需要邮寄的发票
  681. 'where' => "(status=3 or status=4 or (status=2 and untreadStatus=2 ) or ( status=2 and untreadStatus=1 ) ) and isDelete=0 and sid=" . $sid,
  682. 'desc' => 'iid',
  683. 'asArray' => TRUE
  684. ) );
  685. foreach ( $list ['handleInvoice'] as $key => $value ) {
  686. $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  687. $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  688. $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  689. }
  690. }
  691. return $list;
  692. }
  693. /**
  694. * 获得所有未入账发票
  695. * @param number $invoiceTC 发票title
  696. */
  697. public function getInvoiceByUnAccount($invoiceTC = '', $iridExist = false) {
  698. Doo::loadClass ( 'XDeode' );
  699. $XDeode = new XDeode ( 5 );
  700. $title = "";
  701. if (! empty ( $invoiceTC ))
  702. $title = ' and (invoiceTitle like "%' . $invoiceTC . '%" or invoiceCompany like "%' . $invoiceTC . '%" )';
  703. $iridString = ' and irid="" ';
  704. if ($iridExist)
  705. $iridString = ' and irid!="" ';
  706. $list = $this->find ( array ( //
  707. 'where' => "status=2 and printStatus=1 " . $iridString . " and untreadStatus=0 and ( (doPost=1 and postStatus=1) or doPost=0 ) and isDelete=0 " . $title,
  708. 'desc' => 'iid',
  709. 'limit' => 5,
  710. 'asArray' => TRUE
  711. ) );
  712. foreach ( $list as $key => $value ) {
  713. $list [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  714. }
  715. return $list;
  716. }
  717. /**
  718. * 获得与我有关可收款的发票,已经出票的发票
  719. * @param number $sid 开票人ID
  720. */
  721. public function getInvoiceByReceivables($sid = 0) {
  722. Doo::loadClass ( 'XDeode' );
  723. $XDeode = new XDeode ( 5 );
  724. $list ['handleInvoice'] = $this->find ( array (
  725. 'where' => "(status=2 and printStatus=1 and untreadStatus=0 ) and isDelete=0 and sid=" . $sid,
  726. 'desc' => 'iid',
  727. 'asArray' => TRUE
  728. ) );
  729. foreach ( $list ['handleInvoice'] as $key => $value ) {
  730. $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  731. $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  732. // $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  733. }
  734. return $list ['handleInvoice'];
  735. }
  736. /**
  737. * 获取需要邮寄的发票
  738. * @param integer $postStatus 0为获取需要邮寄的发票,1为获取已经邮寄的发票
  739. * @return array|array() 返回相关数据
  740. */
  741. public function getPostByInvoice($postStatus = 0, $desc = "desc") {
  742. Doo::loadClass ( 'XDeode' );
  743. $XDeode = new XDeode ( 5 );
  744. $list = $this->find ( array ( // and untreadStatus=0
  745. 'where' => "postStatus=" . $postStatus . " and printStatus=1 and doPost=1 and status=2 and isDelete=0",
  746. 'limit' => 7,
  747. $desc => 'iid',
  748. 'asArray' => TRUE
  749. ) );
  750. foreach ( $list as $key => $value ) {
  751. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  752. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  753. $list [$key] ['expressCompany'] = '';
  754. $list [$key] ['expressCom'] = '';
  755. if (! empty ( $value ['expressCompany'] )) {
  756. $express = explode ( ":", $value ['expressCompany'] );
  757. $list [$key] ['expressCompany'] = $express [0];
  758. $list [$key] ['expressCom'] = $express [1];
  759. }
  760. }
  761. return $list;
  762. }
  763. /**
  764. * 根据退票状态获得相关数据,iid有值时只获得一条数据
  765. * @param number $untreadStatus 退票状态
  766. * @param number $iid 发票ID
  767. */
  768. public function getMyInvoiceByUntreadStatus($untreadStatus = 1, $iid = 0,$limit=10,$sid=0) {
  769. Doo::loadClass ( 'XDeode' );
  770. $XDeode = new XDeode ( 5 );
  771. if (empty ( $iid )) {
  772. $list = $this->find ( array ( // printStatus=1 and
  773. 'where' => " untreadStatus=" . $untreadStatus . " and status=2 and sid=".$sid,
  774. 'limit' => $limit,
  775. 'asArray' => TRUE
  776. ) );
  777. if ($untreadStatus == 2) {
  778. Doo::loadModel ( 'invoiceOperationLog' );
  779. $invoiceOperationLog = new invoiceOperationLog ();
  780. }
  781. foreach ( $list as $key => $value ) {
  782. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  783. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  784. $list [$key] ['untreadCompany'] = '';
  785. $list [$key] ['untreadCom'] = '';
  786. if (! empty ( $value ['untreadCompany'] )) {
  787. $express = explode ( ":", $value ['untreadCompany'] );
  788. $list [$key] ['untreadCompany'] = $express [0];
  789. $list [$key] ['untreadCom'] = $express [1];
  790. }
  791. if ($untreadStatus == 2) {
  792. $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
  793. }
  794. $list [$key] ['lossDetail'] = array ();
  795. if ($value ['lossIid'] != 0) {
  796. $detail = $this->getOne ( array (
  797. 'where' => "iid=" . $value ['lossIid'],
  798. 'asArray' => TRUE
  799. ) );
  800. $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
  801. $list [$key] ['lossDetail'] = $detail;
  802. }
  803. }
  804. } else {
  805. $list = $this->getOne ( array (
  806. 'where' => "iid=" . $iid . " and printStatus=1 and untreadStatus=" . $untreadStatus . " and status=2",
  807. 'asArray' => TRUE
  808. ) );
  809. }
  810. return $list;
  811. }
  812. /**
  813. * 根据退票状态获得相关数据,iid有值时只获得一条数据
  814. * @param number $untreadStatus 退票状态
  815. * @param number $iid 发票ID
  816. */
  817. public function getInvoiceByUntreadStatus($untreadStatus = 1, $iid = 0,$limit=10) {
  818. Doo::loadClass ( 'XDeode' );
  819. $XDeode = new XDeode ( 5 );
  820. if (empty ( $iid )) {
  821. $list = $this->find ( array ( // printStatus=1 and
  822. 'where' => " untreadStatus=" . $untreadStatus . " and status=2 ",
  823. 'limit' => $limit,
  824. 'asArray' => TRUE
  825. ) );
  826. if ($untreadStatus == 2) {
  827. Doo::loadModel ( 'invoiceOperationLog' );
  828. $invoiceOperationLog = new invoiceOperationLog ();
  829. }
  830. foreach ( $list as $key => $value ) {
  831. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  832. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  833. $list [$key] ['untreadCompany'] = '';
  834. $list [$key] ['untreadCom'] = '';
  835. if (! empty ( $value ['untreadCompany'] )) {
  836. $express = explode ( ":", $value ['untreadCompany'] );
  837. $list [$key] ['untreadCompany'] = $express [0];
  838. $list [$key] ['untreadCom'] = $express [1];
  839. }
  840. if ($untreadStatus == 2) {
  841. $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
  842. }
  843. $list [$key] ['lossDetail'] = array ();
  844. if ($value ['lossIid'] != 0) {
  845. $detail = $this->getOne ( array (
  846. 'where' => "iid=" . $value ['lossIid'],
  847. 'asArray' => TRUE
  848. ) );
  849. $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
  850. $list [$key] ['lossDetail'] = $detail;
  851. }
  852. }
  853. } else {
  854. $list = $this->getOne ( array (
  855. 'where' => "iid=" . $iid . " and printStatus=1 and untreadStatus=" . $untreadStatus . " and status=2",
  856. 'asArray' => TRUE
  857. ) );
  858. }
  859. return $list;
  860. }
  861. /**
  862. * 审批中获取相关数据 包括最近的一条操作记录
  863. * @param number $status.
  864. * @param number $limit.
  865. */
  866. function getInvoiceByProcessStatus($limit = 10, $desc = 'desc') {
  867. Doo::loadClass ( 'XDeode' );
  868. $XDeode = new XDeode ( 5 );
  869. $list = $this->find ( array (
  870. 'where' => " (status=1 or status=2 or status=3 or status=4) and processApprovals!=''",
  871. 'limit' => $limit,
  872. $desc => 'iid',
  873. 'asArray' => TRUE
  874. ) );
  875. Doo::loadModel ( 'invoiceOperationLog' );
  876. $invoiceOperationLog = new invoiceOperationLog ();
  877. foreach ( $list as $key => $value ) {
  878. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  879. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], $value ['status'] );
  880. }
  881. return $list;
  882. }
  883. function getInvoiceByUntreadStatusPage($limit = "0,20", $con = "", $desc = 'desc', $olStatus = "desc",$descField="bindTime") {
  884. if ( empty ( $con ))
  885. return array ();
  886. $listCount = $this->count ( array (
  887. 'where' => $con,
  888. 'asArray' => TRUE
  889. ) );
  890. $sqlArr=array (
  891. 'where' => $con,
  892. $desc => $descField,
  893. 'asArray' => TRUE
  894. );
  895. if ($limit!==false){
  896. $sqlArr+=array (
  897. 'limit' => $limit
  898. );
  899. }
  900. $list = $this->find ( $sqlArr ); // echo $con;
  901. Doo::loadClass ( 'XDeode' );
  902. $XDeode = new XDeode ( 5 );
  903. Doo::loadModel ( 'invoiceReceivables' );
  904. $invoiceReceivables = new invoiceReceivables ();
  905. Doo::loadModel ( 'invoiceOperationLog' );
  906. $invoiceOperationLog = new invoiceOperationLog ();
  907. Doo::loadModel ( 'receipt' );
  908. $receipt = new receipt ();
  909. foreach ( $list as $key => $value ) {
  910. //培训班结算是否完成
  911. $receiptDetail=$receipt->getReceiptByinvoiceTrainId($value['trainId']);
  912. $list[$key]['settlementStatus']=false;
  913. if (!empty($receiptDetail)){
  914. if ($receiptDetail['status']==8||$receiptDetail['status']==9){
  915. $list[$key]['settlementStatus']=true;
  916. }
  917. }
  918. $list [$key] ['count'] = $listCount;
  919. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  920. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  921. $list [$key] ['trainIdKey'] = $XDeode->encode ( $value ['trainId'] );
  922. $list [$key] ['untreadCompany'] = '';
  923. $list [$key] ['untreadCom'] = '';
  924. if (! empty ( $value ['untreadCompany'] )) {
  925. $express = explode ( ":", $value ['untreadCompany'] );
  926. $list [$key] ['untreadCompany'] = $express [0];
  927. $list [$key] ['untreadCom'] = $express [1];
  928. }
  929. $list [$key] ['irList'] = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  930. if ($olStatus == 'desc')
  931. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  932. else
  933. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], $olStatus );
  934. $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
  935. $list [$key] ['OL'] = $invoiceOperationLog->getInvoiceOperationInStatus ( $value ['iid'], '2,3,4' );
  936. // print_r($list [$key] ['OperationLog']);
  937. $list [$key] ['sumPrice'] = 0;
  938. if (! empty ( $list [$key] ['irList'] ))
  939. $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
  940. $list [$key] ['diffPrice'] = $list [$key] ['invoicePrice'];
  941. if (! empty ( $list [$key] ['irList'] [0] ['sumPrice'] ))
  942. $list [$key] ['diffPrice'] = $list [$key] ['invoicePrice'] - $list [$key] ['irList'] [0] ['sumPrice'];
  943. // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  944. $list [$key] ['lossDetail'] = array ();
  945. if ($value ['lossIid'] != 0) {
  946. $detail = $this->getOne ( array (
  947. 'where' => "iid=" . $value ['lossIid'],
  948. 'asArray' => TRUE
  949. ) );
  950. $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
  951. $list [$key] ['lossDetail'] = $detail;
  952. }
  953. $lossDate = strtotime ( "+1 month", strtotime ( $list [$key] ['OperationLog'] ['date'] ) );
  954. $nowDate = strtotime ( 'now' );
  955. $list [$key] ['lossShow'] = false;
  956. if ($lossDate < $nowDate)
  957. $list [$key] ['lossShow'] = true;
  958. }
  959. return $list;
  960. }
  961. /**
  962. * 公司应收款汇总
  963. * @param unknown $con
  964. */
  965. function getInvoiceCompanyStatistics($con = '') {
  966. if (empty ( $con ))
  967. return array ();
  968. $sql = 'select invoicePrice,iid
  969. from ' . $this->_table . '
  970. where ' . $con . '
  971. ';
  972. $query = Doo::db ()->query ( $sql );
  973. $result = $query->fetchAll ();
  974. $iidlist = array ();
  975. $invoicePrice = 0;
  976. foreach ( $result as $value ) {
  977. array_push ( $iidlist, $value ['iid'] );
  978. $invoicePrice += $value ['invoicePrice'];
  979. }
  980. $iidString = implode ( ',', $iidlist );
  981. // 获得已收款发票
  982. if (! empty ( $iidString )) {
  983. $sql = 'select sum(receivablesPrice) as receivablesPrice
  984. from CLD_invoiceReceivables
  985. where iid in (' . $iidString . ') and bindStatus=1
  986. GROUP BY bindStatus';
  987. $query = Doo::db ()->query ( $sql );
  988. $result = $query->fetch ();
  989. } else {
  990. $result ['receivablesPrice'] = 0;
  991. }
  992. return array (
  993. 'invoicePrice' => $invoicePrice,
  994. 'receivablesPrice' => $result ['receivablesPrice'],
  995. 'diffPrice' => $invoicePrice - $result ['receivablesPrice']
  996. );
  997. }
  998. /**
  999. * 获得当前月份办事处入账完成度
  1000. * @param number $cid
  1001. */
  1002. function getInvoiceScheduleByCid($cid = 0, $month = true) {
  1003. if (empty ( $cid ))
  1004. return 0;
  1005. if ($month === false)
  1006. $monthSql = "";
  1007. else {
  1008. $month = date ( "m" );
  1009. $year=date('Y');
  1010. $monthSql = " and Month(date)=" . $month." and Year(date)=".$year;
  1011. }
  1012. // 完成打印
  1013. $recordCount = $this->count ( array (
  1014. 'where' => " status=2 and printStatus=1 and untreadStatus=3 " . $monthSql . " and cid =" . $cid,
  1015. 'asArray' => TRUE
  1016. ) );
  1017. // 当月创建的发票
  1018. $allCount = $this->count ( array (
  1019. 'where' => " isDelete=0 " . $monthSql . " and cid =" . $cid,
  1020. 'asArray' => TRUE
  1021. ) );
  1022. if ($recordCount == 0)
  1023. return 0;
  1024. return $recordCount / $allCount;
  1025. }
  1026. /**
  1027. * 或者办事处成员的完成度
  1028. */
  1029. function getInvoiceScheduleByCidGroupSid($cid = 0) {
  1030. if (empty ( $cid ))
  1031. return array ();
  1032. // 完成发票
  1033. $recordCount = $this->find ( array (
  1034. 'select' => 'count(*) as count,sid',
  1035. 'where' => " status=2 and printStatus=1 and untreadStatus=3 and cid =" . $cid,
  1036. 'groupby' => 'sid',
  1037. 'asArray' => TRUE
  1038. ) );
  1039. // 当月创建的发票
  1040. $allCount = $this->find ( array (
  1041. 'select' => 'count(*) as count,sid',
  1042. 'where' => " isDelete=0 and cid =" . $cid,
  1043. 'groupby' => 'sid',
  1044. 'asArray' => TRUE
  1045. ) );
  1046. $list = array ();
  1047. foreach ( $recordCount as $key => $value ) {
  1048. foreach ( $allCount as $k => $v ) {
  1049. if ($value ['sid'] == $v ['sid']) {
  1050. if ($value ['count'] == 0)
  1051. $list [$value ['sid']] = 0;
  1052. else
  1053. $list [$value ['sid']] = ( int ) (($value ['count'] / $v ['count']) * 100);
  1054. }
  1055. }
  1056. }
  1057. return $list;
  1058. }
  1059. /**
  1060. * 获得个人最新发票信息
  1061. */
  1062. function getInvoiceByNew($sid = 0) {
  1063. if (empty ( $sid ))
  1064. return array ();
  1065. $Detail = $this->getOne ( array (
  1066. 'where' => "sid=" . $sid,
  1067. 'desc' => 'iid',
  1068. 'asArray' => TRUE
  1069. ) );
  1070. return $Detail;
  1071. }
  1072. /**
  1073. * 加密或解密指定字符串
  1074. *
  1075. * @param string $string 要加密或解密的字符串
  1076. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  1077. * @param string $key 加解密的key
  1078. * @param $expiry 超时值
  1079. *
  1080. */
  1081. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  1082. $ckey_length = 4;
  1083. if (! $key) {
  1084. $key = $this->INVOICEKEY;
  1085. }
  1086. $key = md5 ( $key );
  1087. $keya = md5 ( substr ( $key, 0, 16 ) );
  1088. $keyb = md5 ( substr ( $key, 16, 16 ) );
  1089. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  1090. $cryptkey = $keya . md5 ( $keya . $keyc );
  1091. $key_length = strlen ( $cryptkey );
  1092. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  1093. $string_length = strlen ( $string );
  1094. $result = '';
  1095. $box = range ( 0, 255 );
  1096. $rndkey = array ();
  1097. for($i = 0; $i <= 255; $i ++) {
  1098. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  1099. }
  1100. for($j = $i = 0; $i < 256; $i ++) {
  1101. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  1102. $tmp = $box [$i];
  1103. $box [$i] = $box [$j];
  1104. $box [$j] = $tmp;
  1105. }
  1106. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  1107. $a = ($a + 1) % 256;
  1108. $j = ($j + $box [$a]) % 256;
  1109. $tmp = $box [$a];
  1110. $box [$a] = $box [$j];
  1111. $box [$j] = $tmp;
  1112. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  1113. }
  1114. if ($operation == 'DECODE') {
  1115. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  1116. return substr ( $result, 26 );
  1117. } else {
  1118. return '';
  1119. }
  1120. } else {
  1121. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  1122. }
  1123. }
  1124. }
  1125. ?>