InvoiceController.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $verifyId;
  12. public $executeId;
  13. public static $NEW = 0;
  14. public static $NEW2 = 0;
  15. private $INVOICEKEY = "APPROVAL";
  16. function __construct() {
  17. if (isset ( $_COOKIE ["staff"] )) {
  18. if (! empty ( $_COOKIE ["staff"] )) {
  19. Doo::loadModel ( 'staff' );
  20. Doo::loadModel ( 'verify' );
  21. $verify = new verify ();
  22. $staff = new staff ();
  23. Doo::loadModel ( "execute" );
  24. $execute = new execute ();
  25. $verifyList = $verify->find ( array (
  26. 'select' => 'staff',
  27. 'asArray' => true
  28. ) );
  29. $list = array ();
  30. // 判断角色的审批权限
  31. foreach ( $verifyList as $key => $value ) {
  32. $ver = json_decode ( $value ['staff'] );
  33. foreach ( $ver as $k => $v ) {
  34. if ($v [1] == 'ROLE') {
  35. $roleList = json_decode ( $v [3] );
  36. foreach ( $roleList as $t => $g ) {
  37. $gList = explode ( "_", $g );
  38. array_push ( $list, $gList [0] );
  39. // print_r($list);
  40. }
  41. } else
  42. array_push ( $list, $v [0] );
  43. }
  44. }
  45. // 判断执行人的审批权限
  46. $executeList = $execute->find ( array (
  47. 'select' => 'staff',
  48. 'asArray' => true
  49. ) );
  50. $list2 = array ();
  51. foreach ( $executeList as $key => $value ) {
  52. $ver = json_decode ( $value ['staff'] );
  53. foreach ( $ver as $k => $v ) {
  54. array_push ( $list2, $v [0] );
  55. }
  56. }
  57. $eidList = file_get_contents ( "protected/config/execute/execute.ini" );
  58. $eidList = array_filter ( explode ( ",", $eidList ) );
  59. $this->executeId = array_merge ( $list2, $eidList );
  60. $this->verifyId = $list;
  61. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  62. ReceiptController::$NEW = $this->getReceiptCount ();
  63. ReceiptController::$NEW2 = $this->getExeCount ();
  64. return "/";
  65. }
  66. }
  67. Doo::loadCore ( 'uri/DooUriRouter' );
  68. $router = new DooUriRouter ();
  69. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  70. if ($routeRs ['1'] != "login") {
  71. header ( 'Content-Type:text/html;charset=utf-8' );
  72. @header ( "Location: /login" );
  73. }
  74. }
  75. function invoice() {
  76. Doo::loadModel ( 'invoice' );
  77. $invoice = new invoice ();
  78. $pendingInvoice = $invoice->getPendingByInvoice ();
  79. $data ['pendingInvoice'] = $pendingInvoice;
  80. $data ['memu'] = "invoice";
  81. $data ['staff'] = $this->staff;
  82. $data ['receiptMemu'] = 'invoice';
  83. $data ['verifyId'] = $this->verifyId;
  84. $data ['executeId'] = $this->executeId;
  85. $this->render ( "/admin/invoice", $data );
  86. }
  87. function invoiceAdd() {
  88. Doo::loadModel ( 'L_category' );
  89. $lCategory = new L_category ();
  90. $category = $lCategory->find ( array (
  91. 'asArray' => true
  92. ) );
  93. $data ['category'] = $category;
  94. $data ['memu'] = "invoice";
  95. $data ['staff'] = $this->staff;
  96. $data ['receiptMemu'] = 'invoice';
  97. $data ['verifyId'] = $this->verifyId;
  98. $data ['executeId'] = $this->executeId;
  99. $this->render ( "/admin/invoiceAdd", $data );
  100. }
  101. /**
  102. * 提交一份开票申请,并记录下操作日志
  103. *
  104. * @since 1.0.0
  105. * @var integer cid 办事处ID
  106. * @var integer invoiceType 发票类型
  107. * @var integer doPost 是否邮寄
  108. * @var integer invoicePrice 开票金额
  109. * @var string invoiceElement 开票内容
  110. * @var string invoiceTitle 发票抬头
  111. * @var string invoiceCompany 单位名称
  112. * @var string TIN 纳税人识别码
  113. * @var string address 注册地址
  114. * @var string phone 注册电话
  115. * @var string bank 开户银行
  116. * @var string bankAccount 银行账户
  117. * @var string recipients 收件人
  118. * @var string recipientsPhone 收件人手机/电话
  119. * @var string recipientsAddress 收件地址
  120. * @var string mailItems 邮寄物品
  121. * @var string remark 备注
  122. * @return string 返回跳转开票主页路径
  123. */
  124. function invoiceAddDo() {
  125. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  126. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  127. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  128. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  129. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  130. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  131. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  132. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  133. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  134. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  135. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  136. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  137. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  138. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  139. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  140. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  141. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  142. if (! empty ( $cid ) && ! empty ( $invoicePrice ) && ! empty ( $invoiceElement )) {
  143. Doo::loadModel ( 'invoice' );
  144. $invoice = new invoice ();
  145. Doo::loadModel ( 'L_category' );
  146. $lCategory = new L_category ();
  147. Doo::loadModel ( 'invoiceManage' );
  148. $invoiceManage = new invoiceManage ();
  149. Doo::loadModel ( 'invoiceOperationLog' );
  150. $invoiceOperationLog = new invoiceOperationLog ();
  151. $categoryDetil = $lCategory->getOne ( array (
  152. 'SELECT' => 'title',
  153. 'where' => 'cid=' . $cid,
  154. 'asArray' => true
  155. ) );
  156. $invoiceManageDetail = $invoiceManage->getOne ( array (
  157. 'SELECT' => 'title',
  158. 'where' => 'mold="发票审批"',
  159. 'asArray' => true
  160. ) );
  161. $invoice->cid = $cid;
  162. $invoice->categoryName = $categoryDetil ['title'];
  163. $invoice->invoiceElement = $invoiceElement;
  164. $invoice->invoicePrice = $invoicePrice;
  165. $invoice->invoiceType = $invoiceType;
  166. if ($invoiceType == 0)
  167. $invoice->invoiceTitle = $invoiceTitle;
  168. elseif ($invoiceType == 1) {
  169. $invoice->invoiceCompany = $invoiceCompany;
  170. $invoice->TIN = $TIN;
  171. $invoice->address = $address;
  172. $invoice->phone = $phone;
  173. $invoice->bank = $bank;
  174. $invoice->bankAccount = $bankAccount;
  175. }
  176. $invoice->doPost = $doPost;
  177. if ($doPost == 1) {
  178. $invoice->recipients = $recipients;
  179. $invoice->recipientsPhone = $recipientsPhone;
  180. $invoice->recipientsAddress = $recipientsAddress;
  181. $invoice->mailItems = $mailItems;
  182. }
  183. $invoice->status = 1;
  184. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  185. $invoice->date = date ( "Y-m-d H:i:s" );
  186. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  187. $invoice->sid = $this->staff [0] ['sid'];
  188. $invoice->userName = $this->staff [0] ['username'];
  189. $invoice->invoiceManage = $invoiceManageDetail ['staff'];
  190. $staffId = $a = json_decode ( $invoiceManageDetail ['staff'] );
  191. $invoice->pendingApprovals = $staffId [0] [0];
  192. $invoice->remark = $remark;
  193. $iid = $invoice->insert ();
  194. $item = array (
  195. 'date' => date ( "Y-m-d H:i:s" ),
  196. 'operation' => "创建",
  197. 'status' => 1,
  198. 'img' => $this->staff [0] ['avatar'],
  199. 'username' => $this->staff [0] ['username'],
  200. 'uid' => $this->staff [0] ['sid'],
  201. 'category' => $this->staff [0] ['category'],
  202. 'iid' => $iid
  203. );
  204. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  205. $item = array (
  206. 'date' => date ( "Y-m-d H:i:s" ),
  207. 'operation' => "提交审批",
  208. 'status' => 1,
  209. 'img' => $this->staff [0] ['avatar'],
  210. 'username' => $this->staff [0] ['username'],
  211. 'uid' => $this->staff [0] ['sid'],
  212. 'category' => $this->staff [0] ['category'],
  213. 'iid' => $iid
  214. );
  215. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  216. }
  217. return "/invoice";
  218. }
  219. function invoiceApproval() {
  220. Doo::loadModel ( 'invoice' );
  221. $invoice = new invoice ();
  222. Doo::loadClass ( 'XDeode' );
  223. $XDeode = new XDeode ( 5 );
  224. Doo::loadModel ( 'staff' );
  225. $staff = new staff ();
  226. $invoiceList = $invoice->find ( array (
  227. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  228. 'desc' => 'iid',
  229. 'asArray' => true
  230. ) );
  231. foreach ( $invoiceList as $key => $value ) {
  232. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  233. $lastApprover = json_decode ( $value ['processApprovals'], true );
  234. if (! empty ( $lastApprover )) {
  235. $lastApproverKey = array_keys ( $lastApprover );
  236. $lastApprover = end ( $lastApprover );
  237. $staffDetail = $staff->getOne ( array (
  238. 'where' => 'sid=' . end ( $lastApproverKey ),
  239. 'asArray' => true
  240. ) );
  241. $lastApprover ['username'] = $staffDetail ['username'];
  242. }
  243. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  244. }
  245. $data ['invoiceList'] = $invoiceList;
  246. $data ['memu'] = "invoice";
  247. $data ['staff'] = $this->staff;
  248. $data ['receiptMemu'] = 'invoiceApproval';
  249. $data ['verifyId'] = $this->verifyId;
  250. $data ['executeId'] = $this->executeId;
  251. $this->render ( "/admin/invoiceApproval", $data );
  252. }
  253. function invoiceDetail() {
  254. Doo::loadClass ( 'XDeode' );
  255. $XDeode = new XDeode ( 5 );
  256. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  257. $iid = $XDeode->decode ( $iid );
  258. if (! is_numeric ( $iid ))
  259. die ( 'illegal request' );
  260. Doo::loadModel ( 'invoice' );
  261. $invoice = new invoice ();
  262. Doo::loadModel ( 'invoiceOperationLog' );
  263. $invoiceOperationLog = new invoiceOperationLog ();
  264. $invoiceDetail = $invoice->getOne ( array (
  265. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  266. 'asArray' => true
  267. ) );
  268. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  269. $data ['invoiceDetail'] = $invoiceDetail;
  270. $data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  271. $data ['INVOICEKEY'] = $this->authcode ( $invoiceDetail ['iid'], '' );
  272. $data ['memu'] = "invoice";
  273. $data ['staff'] = $this->staff;
  274. $data ['receiptMemu'] = 'invoiceApproval';
  275. $data ['verifyId'] = $this->verifyId;
  276. $data ['executeId'] = $this->executeId;
  277. $this->render ( "/admin/invoiceApprovalDetail", $data );
  278. }
  279. /**
  280. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  281. *
  282. * @since 1.0.0
  283. * @var integer iid 开票ID 已加密
  284. * @var integer status 发票审批状态
  285. * @var integer opintion 审批发票的意见
  286. * @return string 如操作成功返回审批首页
  287. */
  288. function invoiceApprovalDo() {
  289. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  290. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  291. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  292. $iid = $this->authcode ( $iid );
  293. if (! is_numeric ( $iid ))
  294. die ( 'illegal request' );
  295. if (! empty ( $iid ) && ! empty ( $status ) && ! empty ( $opinion )) {
  296. if (! ($status == 2 || $status == 3 || $status == 4))
  297. die ( 'illegal request' );
  298. Doo::loadModel ( 'invoice' );
  299. $invoice = new invoice ();
  300. Doo::loadModel ( 'invoiceOperationLog' );
  301. $invoiceOperationLog = new invoiceOperationLog ();
  302. $invoiceDetail = $invoice->getOne ( array (
  303. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  304. 'asArray' => true
  305. ) );
  306. if (empty ( $invoiceDetail ))
  307. die ( 'illegal request' );
  308. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  309. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  310. if ($status == 3) {
  311. $invoice->status = $status;
  312. $item = array (
  313. 'operation' => "退回"
  314. );
  315. } else {
  316. if (empty ( $processApprovals )) {
  317. $processApprovals = array (
  318. $this->staff [0] ['sid'] => array (
  319. 'date' => date ( "Y-m-d H:i:s" ),
  320. 'opinion' => $opinion,
  321. 'status' => $status
  322. )
  323. );
  324. if ($status != 4 && isset ( $invoiceManage [1] ))
  325. $invoice->pendingApprovals = $invoiceManage [1] [0];
  326. $invoice->processApprovals = json_encode ( $processApprovals );
  327. } else {
  328. $processApprovals [$this->staff [0] ['sid']] = array (
  329. 'date' => date ( "Y-m-d H:i:s" ),
  330. 'opinion' => $opinion,
  331. 'status' => $status
  332. );
  333. $pendingApprovals = 0;
  334. foreach ( $invoiceManage as $key => $value ) {
  335. if ($value [0] == $this->staff [0] ['sid']) {
  336. if (isset ( $invoiceManage [$key + 1] ))
  337. $pendingApprovals = $invoiceManage [$key + 1] [0];
  338. break;
  339. }
  340. }
  341. if ($status != 4 && ! empty ( $pendingApprovals ))
  342. $invoice->pendingApprovals = $pendingApprovals;
  343. $invoice->processApprovals = json_encode ( $processApprovals );
  344. }
  345. $item = array (
  346. 'operation' => "同意"
  347. );
  348. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  349. $invoice->status = $status;
  350. $invoice->pendingApprovals = 0;
  351. } elseif ($status == 4) {
  352. $invoice->status = $status;
  353. $item = array (
  354. 'operation' => "终止"
  355. );
  356. }
  357. }
  358. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  359. $invoice->update ( array (
  360. 'where' => 'iid=' . $iid
  361. ) );
  362. $item += array (
  363. 'date' => date ( "Y-m-d H:i:s" ),
  364. 'img' => $this->staff [0] ['avatar'],
  365. 'username' => $this->staff [0] ['username'],
  366. 'uid' => $this->staff [0] ['sid'],
  367. 'category' => $this->staff [0] ['category'],
  368. 'status' => $status,
  369. 'iid' => $iid
  370. );
  371. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  372. return '/invoiceApproval';
  373. }
  374. die ( 'illegal request' );
  375. }
  376. /**
  377. * 展示需要打印的发票数据
  378. *
  379. * @since 1.0.0
  380. */
  381. function invoicePrint() {
  382. Doo::loadModel ( 'invoice' );
  383. $invoice = new invoice ();
  384. Doo::loadClass ( 'XDeode' );
  385. $XDeode = new XDeode ( 5 );
  386. Doo::loadModel ( 'staff' );
  387. $staff = new staff ();
  388. $toPrint = $invoice->find ( array (
  389. 'where' => 'status=2 ',
  390. 'desc' => 'iid',
  391. 'asArray' => true
  392. ) );
  393. $printed = $invoice->find ( array (
  394. 'where' => 'status=5 ',
  395. 'desc' => 'iid',
  396. 'asArray' => true
  397. ) );
  398. foreach ( $toPrint as $key => $value ) {
  399. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  400. $lastApprover = json_decode ( $value ['processApprovals'], true );
  401. if (! empty ( $lastApprover )) {
  402. $lastApproverKey = array_keys ( $lastApprover );
  403. $lastApprover = end ( $lastApprover );
  404. $staffDetail = $staff->getOne ( array (
  405. 'where' => 'sid=' . end ( $lastApproverKey ),
  406. 'asArray' => true
  407. ) );
  408. $lastApprover ['username'] = $staffDetail ['username'];
  409. }
  410. $toPrint [$key] ['lastApprover'] = $lastApprover;
  411. }
  412. foreach ( $printed as $key => $value ) {
  413. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  414. $lastApprover = json_decode ( $value ['processApprovals'], true );
  415. if (! empty ( $lastApprover )) {
  416. $lastApproverKey = array_keys ( $lastApprover );
  417. $lastApprover = end ( $lastApprover );
  418. $staffDetail = $staff->getOne ( array (
  419. 'where' => 'sid=' . end ( $lastApproverKey ),
  420. 'asArray' => true
  421. ) );
  422. $lastApprover ['username'] = $staffDetail ['username'];
  423. }
  424. $printed [$key] ['lastApprover'] = $lastApprover;
  425. }
  426. $data ['printed'] = $printed;
  427. $data ['toPrint'] = $toPrint;
  428. $data ['memu'] = "invoice";
  429. $data ['staff'] = $this->staff;
  430. $data ['receiptMemu'] = 'invoicePrint';
  431. $data ['verifyId'] = $this->verifyId;
  432. $data ['executeId'] = $this->executeId;
  433. $this->render ( "/admin/invoicePrint", $data );
  434. }
  435. /**
  436. * 展示发票打印的详情页面
  437. *
  438. * @since 1.0.0
  439. */
  440. function invoicePrintDetail() {
  441. Doo::loadClass ( 'XDeode' );
  442. $XDeode = new XDeode ( 5 );
  443. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  444. $iid = $XDeode->decode ( $iid );
  445. if (! is_numeric ( $iid ))
  446. die ( 'illegal request' );
  447. Doo::loadModel ( 'invoice' );
  448. $invoice = new invoice ();
  449. Doo::loadModel ( 'invoiceOperationLog' );
  450. $invoiceOperationLog = new invoiceOperationLog ();
  451. $invoiceDetail = $invoice->getOne ( array (
  452. 'where' => 'status=2 and iid=' . $iid,
  453. 'asArray' => true
  454. ) );
  455. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  456. $data ['invoiceDetail'] = $invoiceDetail;
  457. $data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  458. $data ['INVOICEKEY'] = $this->authcode ( $invoiceDetail ['iid'], '' );
  459. $data ['memu'] = "invoice";
  460. $data ['staff'] = $this->staff;
  461. $data ['receiptMemu'] = 'invoicePrint';
  462. $data ['verifyId'] = $this->verifyId;
  463. $data ['executeId'] = $this->executeId;
  464. $this->render ( "/admin/invoicePrintDetail", $data );
  465. }
  466. /**
  467. * 填写票号并完成打印
  468. * @since 1.0.0
  469. */
  470. function invoicePrintDo() {
  471. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  472. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  473. $iid = $this->authcode ( $iid );
  474. if (! is_numeric ( $iid ))
  475. die ( 'illegal request' );
  476. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  477. Doo::loadModel ( 'invoice' );
  478. $invoice = new invoice ();
  479. Doo::loadModel ( 'invoiceOperationLog' );
  480. $invoiceOperationLog = new invoiceOperationLog ();
  481. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  482. if (empty ( $invoicePrintDetail ))
  483. die ( 'illegal request' );
  484. $item = array (
  485. 'iid' => $iid,
  486. 'status' => 5,
  487. 'updateTime'=>date ( "Y-m-d H:i:s" ),
  488. 'printTime'=>date ( "Y-m-d H:i:s" ),
  489. 'invoiceNo' => $invoiceNo
  490. );
  491. $invoice->setPrintByInvoice ( $item );
  492. $item = array (
  493. 'date' => date ( "Y-m-d H:i:s" ),
  494. 'operation' => $invoiceNo,
  495. 'status' => 5,
  496. 'img' => $this->staff [0] ['avatar'],
  497. 'username' => $this->staff [0] ['username'],
  498. 'uid' => $this->staff [0] ['sid'],
  499. 'category' => $this->staff [0] ['category'],
  500. 'iid' => $iid
  501. );
  502. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  503. return "/invoicePrint";
  504. }
  505. }
  506. /**
  507. * 需要邮寄的发票
  508. * @since 1.0.0
  509. */
  510. function invoicePost() {
  511. Doo::loadModel ( 'invoice' );
  512. $invoice = new invoice ();
  513. $invoicePost=$invoice->getPostByInvoice();
  514. $data ['invoicePost'] = $invoicePost;
  515. $data ['memu'] = "invoice";
  516. $data ['staff'] = $this->staff;
  517. $data ['receiptMemu'] = 'invoicePost';
  518. $data ['verifyId'] = $this->verifyId;
  519. $data ['executeId'] = $this->executeId;
  520. $this->render ( "/admin/invoicePost", $data );
  521. }
  522. private function getExeCount() {
  523. Doo::loadModel ( 'receipt' );
  524. $receipt = new receipt ();
  525. $receiptList = $receipt->find ( array (
  526. 'where' => '(executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff NOT LIKE \'%' . $this->staff [0] ['sid'] . '%\' ) and (status=1 or status=6)',
  527. 'desc' => 'rid',
  528. 'asArray' => true
  529. ) );
  530. return count ( $receiptList );
  531. }
  532. private function getReceiptCount() {
  533. $status = 2;
  534. $year = date ( 'Y' );
  535. Doo::loadModel ( 'receipt' );
  536. $receipt = new receipt ();
  537. Doo::loadModel ( 'verify' );
  538. $dateCondition = " and Year(date) =" . $year;
  539. $approvalCondition = ' and nowStaff like "%' . $this->staff [0] ['sid'] . '%" ';
  540. $receiptList = $receipt->find ( array (
  541. 'where' => ' status=' . $status . $dateCondition . $approvalCondition,
  542. 'desc' => 'rid',
  543. 'asArray' => true
  544. ) );
  545. return count ( $receiptList );
  546. }
  547. function _GetFileEXT($filename) {
  548. $pics = explode ( '.', $filename );
  549. $num = count ( $pics );
  550. return $pics [$num - 1];
  551. }
  552. /**
  553. * 获取get或者POST值
  554. *
  555. * @param string $name 属性名称
  556. * @return fixed 值
  557. */
  558. function get_args($name) {
  559. if (isset ( $_GET [$name] )) {
  560. if (is_array ( $_GET [$name] ))
  561. return $_GET [$name];
  562. else
  563. return addslashes ( $_GET [$name] );
  564. } elseif (isset ( $_POST [$name] )) {
  565. if (is_array ( $_POST [$name] ))
  566. return $_POST [$name];
  567. else
  568. return addslashes ( $_POST [$name] );
  569. } else
  570. return false;
  571. }
  572. /**
  573. * 加密或解密指定字符串
  574. *
  575. * @param string $string 要加密或解密的字符串
  576. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  577. * @param string $key 加解密的key
  578. * @param $expiry 超时值
  579. *
  580. */
  581. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  582. $ckey_length = 4;
  583. if (! $key) {
  584. $key = $this->INVOICEKEY;
  585. }
  586. $key = md5 ( $key );
  587. $keya = md5 ( substr ( $key, 0, 16 ) );
  588. $keyb = md5 ( substr ( $key, 16, 16 ) );
  589. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  590. $cryptkey = $keya . md5 ( $keya . $keyc );
  591. $key_length = strlen ( $cryptkey );
  592. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  593. $string_length = strlen ( $string );
  594. $result = '';
  595. $box = range ( 0, 255 );
  596. $rndkey = array ();
  597. for($i = 0; $i <= 255; $i ++) {
  598. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  599. }
  600. for($j = $i = 0; $i < 256; $i ++) {
  601. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  602. $tmp = $box [$i];
  603. $box [$i] = $box [$j];
  604. $box [$j] = $tmp;
  605. }
  606. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  607. $a = ($a + 1) % 256;
  608. $j = ($j + $box [$a]) % 256;
  609. $tmp = $box [$a];
  610. $box [$a] = $box [$j];
  611. $box [$j] = $tmp;
  612. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  613. }
  614. if ($operation == 'DECODE') {
  615. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  616. return substr ( $result, 26 );
  617. } else {
  618. return '';
  619. }
  620. } else {
  621. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  622. }
  623. }
  624. }
  625. class ReceiptController {
  626. public static $NEW = 0;
  627. public static $NEW2 = 0;
  628. }
  629. ?>