"iid=" . $iid, 'asArray' => TRUE ); if (! empty ( $select )) $condition += array ( 'select' => $select ); $Detail = array (); if (is_numeric ( $iid ) && ! empty ( $iid )) $Detail = $this->getOne ( $condition ); $Detail ['expressCompany'] = ''; $Detail ['expressCom'] = ''; if (isset ( $Detail ['expressCompany'] ) && ! empty ( $Detail ['expressCompany'] )) { $express = explode ( ":", $Detail ['expressCompany'] ); $Detail ['expressCompany'] = $express [0]; $Detail ['expressCom'] = $express [1]; } $Detail ['iidKey'] = $this->authcode ( $Detail ['iid'], '' ); Doo::loadModel ( 'L_category' ); $lCategory = new L_category (); $Detail ['category'] = $lCategory->getCategory (); return $Detail; } /** * 获取单个可以打印的发票数据 * @param number $iid 发票id * @param number $select 需要获取的字段,为空获取全部数据 * @return array|array() 返回发票数据 */ public function getInvoiceByPrint($iid = 0, $select = "") { $condition = array ( 'where' => "iid= '" . $iid . "' and status=2", 'asArray' => TRUE ); if (! empty ( $select )) $condition += array ( 'select' => $select ); $detail = array (); if (! empty ( $iid ) && is_numeric ( $iid )) $detail = $this->getOne ( $condition ); return $detail; } /** * 添加一个发票并进入审批状态 * @param array $item 发票相关数据 * @return number 返回发票ID */ public function addInvoice($item = array()) { $lid = 0; if (is_array ( $item ) && ! empty ( $item )) { foreach ( $item as $key => $value ) { $this->$key = $value; } $lid = $this->insert (); } return $lid; } /** * 根据参数字段更新相应字段(主键ID必须传) * @param array $item 相关需要更新的字段信息 * @return number 返回发票ID */ public function setInvoiceByCondition($item = array()) { $lid = 0; if (is_array ( $item ) && ! empty ( $item )) { foreach ( $item as $key => $value ) { $this->$key = $value; } $lid = $this->update (); } return $lid; } /** * 根据管理组和发票当前状态获得打印发票数据;其中当iid为空时获取所有发票数据,反之获取1条数据 * @param number $sid 管理组人员ID * @param number $status 状态 为0时获取可以打印数据,为1时获取已经完成打印数据 * @param number $iid 发票ID * @return array|array() 返回所有发票数据,当iid有值时返回一条数据 */ public function getPrintInvoiceByManage($sid = 0, $status = 0, $iid = 0) { $list = array (); if (! empty ( $sid ) && empty ( $iid )) $list = $this->find ( array ( 'where' => "status=2 and printStatus=" . $status . " and moldManage like '%[\"" . $sid . "\",%'", 'desc' => 'iid', 'asArray' => TRUE ) ); elseif (! empty ( $sid ) && ! empty ( $iid )) $list = $this->getOne ( array ( 'where' => "status=2 and printStatus=" . $status . " and moldManage like '%[\"" . $sid . "\",%' and iid=" . $iid, 'asArray' => TRUE ) ); return $list; } /** * 获得与我相关的发票数据,其中包含 处理中,待处理,最旧入账等数据;当iid有值时获取一条关于sid的发票 * @param number $sid 用户ID * @param number $iid 发票ID * @return array|array() */ public function getMyInvoice($sid = 0, $iid = 0) { Doo::loadModel ( 'invoiceOperationLog' ); $invoiceOperationLog = new invoiceOperationLog (); Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); $list = array (); if (! empty ( $iid )) { $list = $this->getOne ( array ( 'where' => " sid=" . $sid . " and iid=" . $iid, 'asArray' => TRUE ) ); } elseif (! empty ( $sid ) && empty ( $iid )) { $list ['pendingInvoice'] = array (); $list ['handleInvoice'] = array (); $list ['pendingInvoice'] = $this->find ( array ( 'where' => "((status=1) or (status=2 and printStatus=0) or ( status=2 and printStatus=1 and untreadStatus=1) ) and sid=" . $sid, 'desc' => 'iid', 'asArray' => TRUE ) ); foreach ( $list ['pendingInvoice'] as $key => $value ) { $list ['pendingInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' ); } $list ['handleInvoice'] = $this->find ( array ( 'where' => "(status=3 or status=4 or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 ) ) and isDelete=0 and sid=" . $sid, 'desc' => 'iid', 'asArray' => TRUE ) ); foreach ( $list ['handleInvoice'] as $key => $value ) { $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' ); $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] ); $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' ); } } return $list; } /** * 获取需要邮寄的发票 * @param integer $postStatus 0为获取需要邮寄的发票,1为获取已经邮寄的发票 * @return array|array() 返回相关数据 */ public function getPostByInvoice($postStatus = 0) { $list = $this->find ( array ( 'where' => "postStatus=" . $postStatus . " and doPost=1 and status=2", 'asArray' => TRUE ) ); foreach ( $list as $key => $value ) { $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' ); $list [$key] ['expressCompany'] = ''; $list [$key] ['expressCom'] = ''; if (! empty ( $value ['expressCompany'] )) { $express = explode ( ":", $value ['expressCompany'] ); $list [$key] ['expressCompany'] = $express [0]; $list [$key] ['expressCom'] = $express [1]; } } return $list; } /** * 根据退票状态获得相关数据,iid有值时只获得一条数据 * @param number $untreadStatus 退票状态 * @param number $iid 发票ID */ public function getInvoiceByUntreadStatus( $untreadStatus = 1,$iid = 0) { if (empty ( $iid )) { $list = $this->find ( array ( 'where' => " printStatus=1 and untreadStatus=".$untreadStatus." and status=2 ", 'asArray' => TRUE ) ); if ($untreadStatus==2){ Doo::loadModel ( 'invoiceOperationLog' ); $invoiceOperationLog = new invoiceOperationLog (); } foreach ( $list as $key => $value ) { $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' ); $list [$key] ['untreadCompany'] = ''; $list [$key] ['untreadCom'] = ''; if (! empty ( $value ['untreadCompany'] )) { $express = explode ( ":", $value ['untreadCompany'] ); $list [$key] ['untreadCompany'] = $express [0]; $list [$key] ['untreadCom'] = $express [1]; } if ($untreadStatus==2){ $list[$key] ['OperationLog']=$invoiceOperationLog->getInvoiceOperationByStatus($value['iid'],6); } } } else { $list = $this->getOne ( array ( 'where' => "iid=" . $iid . " and printStatus=1 and untreadStatus=".$untreadStatus." and status=2", 'asArray' => TRUE ) ); } return $list; } /** * 加密或解密指定字符串 * * @param string $string 要加密或解密的字符串 * @param string $operation 当取值为'DECODE'时表示解密,否则为加密 * @param string $key 加解密的key * @param $expiry 超时值 * */ function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { $ckey_length = 4; if (! $key) { $key = $this->INVOICEKEY; } $key = md5 ( $key ); $keya = md5 ( substr ( $key, 0, 16 ) ); $keyb = md5 ( substr ( $key, 16, 16 ) ); $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : ''; $cryptkey = $keya . md5 ( $keya . $keyc ); $key_length = strlen ( $cryptkey ); $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string; $string_length = strlen ( $string ); $result = ''; $box = range ( 0, 255 ); $rndkey = array (); for($i = 0; $i <= 255; $i ++) { $rndkey [$i] = ord ( $cryptkey [$i % $key_length] ); } for($j = $i = 0; $i < 256; $i ++) { $j = ($j + $box [$i] + $rndkey [$i]) % 256; $tmp = $box [$i]; $box [$i] = $box [$j]; $box [$j] = $tmp; } for($a = $j = $i = 0; $i < $string_length; $i ++) { $a = ($a + 1) % 256; $j = ($j + $box [$a]) % 256; $tmp = $box [$a]; $box [$a] = $box [$j]; $box [$j] = $tmp; $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) ); } if ($operation == 'DECODE') { if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) { return substr ( $result, 26 ); } else { return ''; } } else { return $keyc . str_replace ( '=', '', base64_encode ( $result ) ); } } } ?>