InvoiceController.php 21 KB

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