123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890 |
- <?php
- Doo::loadCore ( 'db/DooModel' );
- /**
- * 发票审批相关信息及其操作业务逻辑
- * @author CP.
- * @version 1.0
- * @namespace invoice
- * @package invoiceModel
- */
- class invoice extends DooModel {
- private $INVOICEKEY = "APPROVAL";
- private $FUZZY = 'FUZZY';
- private $EXACTLY = "EXACTLY";
-
- /**
- *
- * @var integer $iid 发票ID
- */
- public $iid;
- public $isid;
- public $trainId;
- public $lossIid;
- public $ipSource;
- /**
- *
- * @var integer $status 审批状态
- */
- public $status;
- /**
- *
- * @var string $invoiceManage 当前审批组人员
- */
- public $printStatus;
- public $postStatus;
- public $invoiceManage;
- /**
- *
- * @var string $pendingApprovals 当前需要审批的人
- */
- public $pendingApprovals;
- /**
- *
- * @var string $processApprovals 已经审批过的人员
- */
- public $processApprovals;
- /**
- *
- * @var string $invoiceSerial 发票单号
- */
- public $invoiceSerial;
- /**
- *
- * @var integer $invoicePrice 发票金额
- */
- public $invoicePrice;
- public $invoiceQuantity;
- public $invoiceUnitPrice;
-
- /**
- * 管理组人员:发票打印,
- * @var unknown
- */
- public $moldManage;
- /**
- *
- * @var integer $cid 办事处ID
- */
- public $cid;
- /**
- *
- * @var string $categoryName 办事处名称
- */
- public $categoryName;
- /**
- *
- * @var integer $sid 提交发票人ID
- */
- public $sid;
- /**
- *
- * @var string $userName 提交人名字
- */
- public $printer;
- public $userName;
- /**
- *
- * @var string $remark 备注
- */
- public $remark;
- /**
- *
- * @var string $invoiceElement 发票内容
- */
- public $invoiceElement;
- /**
- *
- * @var string $invoiceType 发票类型
- */
- public $invoiceType;
- /**
- *
- * @var string $invoiceTitle 发票抬头
- */
- public $invoiceTitle;
- /**
- *
- * @var string $invoiceCompany 开票公司
- */
- public $invoiceCompany;
- /**
- *
- * @var string $invoiceNo 发票号
- */
- public $invoiceNo;
- /**
- *
- * @var string $TIN 纳税人识别码
- */
- public $TIN;
- /**
- *
- * @var string $address 注册地址
- */
- public $address;
- /**
- *
- * @var string $phone 电话
- */
- public $phone;
- /**
- *
- * @var string $bank 开户银行
- */
- public $bank;
- /**
- *
- * @var string $bankAccount 银行账户
- */
- public $bankAccount;
- /**
- *
- * @var integer $doPost 邮寄
- */
- public $doPost;
- /**
- *
- * @var string $recipients 收件人
- */
- public $recipients;
- /**
- *
- * @var string $recipientsPhone 收件人电话
- */
- public $recipientsPhone;
- /**
- *
- * @var string $recipientsAddress 收件地址
- */
- public $recipientsAddress;
- /**
- *
- * @var string $mailItems 邮寄物品
- */
- public $mailItems;
- public $mailItemsJson;
- public $expressCompany;
- public $expressNumber;
- public $actualItems;
- public $poster;
- public $untreadReason;
- public $untreadPost;
- public $untreadCompany;
- public $untreadNumber;
- public $untreadItems;
- public $untreadStatus;
- public $irid;
- public $bindTime;
- /**
- *
- * @var date $date 提交时间
- */
- public $date;
- public $isDelete;
- public $approvalTime;
- /**
- *
- * @var date $updateTime 更新时间
- */
- public $updateTime;
- /**
- *
- * @var date $printTime 打印时间
- */
- public $printTime;
- public $postTime;
- public $_table = 'CLD_invoice';
- public $_primarykey = 'iid';
- public $_fields = array (
- 'iid',
- 'isid',
- 'trainId',
- 'ipSource',
- 'lossIid',
- 'invoiceManage',
- 'pendingApprovals',
- 'processApprovals',
- 'invoiceSerial',
- 'status',
- 'printStatus',
- 'postStatus',
- 'untreadStatus',
- 'invoiceQuantity',
- 'invoiceUnitPrice',
- 'invoicePrice',
- 'moldManage',
- 'cid',
- 'categoryName',
- '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',
- 'sid',
- 'userName',
- 'printer',
- 'date',
- 'isDelete',
- 'approvalTime',
- 'updateTime',
- 'printTime',
- 'postTime',
- 'bindTime'
- );
- /**
- * 根据发票ID获取一条发票数据
- * @param number $iid 发票ID
- * @param number $select 需要获取的字段,为空获取全部数据
- * @return array|array() 返回发票数据
- */
- public function getInvoiceByIid($iid = 0, $select = "") {
- if (! is_numeric ( $iid ))
- $iid = $this->authcode ( $iid );
-
- $condition = array (
- 'where' => "iid=" . $iid,
- 'asArray' => TRUE
- );
- if (! empty ( $select ))
- $condition += array (
- 'select' => $select
- );
-
- $Detail = array ();
- if (is_numeric ( $iid ) && ! empty ( $iid ))
- $Detail = $this->getOne ( $condition );
-
- if (empty ( $Detail ))
- return $Detail;
- if (isset ( $Detail ['expressCompany'] ) && ! empty ( $Detail ['expressCompany'] )) {
- $express = explode ( ":", $Detail ['expressCompany'] );
- $Detail ['expressCompany'] = $express [0];
- $Detail ['expressCom'] = $express [1];
- } else {
- $Detail ['expressCompany'] = '';
- $Detail ['expressCom'] = '';
- }
-
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
-
- $Detail ['iidKeyUrl'] = $XDeode->encode ( $Detail ['iid'] );
-
- $Detail ['iidKey'] = $this->authcode ( $Detail ['iid'], '' );
- Doo::loadModel ( 'L_category' );
- $lCategory = new L_category ();
- $Detail ['category'] = $lCategory->getCategory ();
- return $Detail;
- }
- /**
- * 根据多个iid获得多个发票
- * @param number $iid
- */
- function getInvoiceInIid($iid = 0, $select = '') {
- if (empty ( $iid ))
- die ( 'illegal request' );
-
- $condition = array (
- 'where' => "iid in ( " . $iid . ")",
- 'asArray' => TRUE
- );
-
- if (! empty ( $select ))
- $condition += array (
- 'select' => $select
- );
- $list = $this->find ( $condition );
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- foreach ($list as $key=>$value){
- $list [$key]['iidKey'] = $XDeode->encode ( $value ['iid'] );
- }
- return $list;
- }
- function setInvoiceLoss($iid = "") {
- if (empty ( $iid ))
- return 0;
-
- $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`)
- 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;
- $query = Doo::db ()->query ( $sql );
-
- return Doo::db ()->lastInsertId ();
- }
- function getInvoiceByInvoiceNo($invoiceNo = '') {
- if (empty ( $invoiceNo ))
- return array ();
- $detail = $this->getOne ( array (
- 'where' => "invoiceNo= '" . $invoiceNo . "'",
- 'asArray' => TRUE
- ) );
-
- return $detail;
- }
-
- /**
- * 根据标题或者开票单位获得相关信息 - 准确查询
- * @param string $title 查询条件
- * @param string $query 默认模糊查询
- */
- public function getInvoiceByTitle($title = "", $query = "FUZZY", $cond = '', $fkq = false) {
- $detail = array ();
- if (! empty ( $title )) {
- $condition = array (
- 'asArray' => TRUE
- );
-
- if ($query == $this->FUZZY)
- $condition += array (
- 'where' => " (invoiceTitle like '%" . $title . "%' or invoiceCompany like '%" . $title . "%') " . $cond
- );
- else
- $condition += array (
- 'where' => "(invoiceTitle = '" . $title . "' or invoiceCompany= '" . $title . "') " . $cond
- );
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- if ($fkq) {
-
- $detail = $this->find ( $condition );
-
- foreach ( $detail as $key => $value ) {
- $detail [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
- $detail [$key] ['iidKeyXD'] = $XDeode->encode ( $value ['iid'] );
- }
- } else {
- $detail = $this->getOne ( $condition );
- if (! empty ( $detail )) {
-
- $detail ['iidKey'] = $this->authcode ( $detail ['iid'], '' );
- $detail ['iidKeyXD'] = $XDeode->encode ( $detail ['iid'] );
- }
- }
- }
-
- return $detail;
- }
- public function getInvoiceByIsid($iid = "", $sid = 0) {
- if (empty ( $iid ) || empty ( $sid ))
- return array ();
-
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $iid = $XDeode->decode ( $iid );
- if (! is_numeric ( $iid ))
- return array ();
-
- $detail = $this->getOne ( array (
- 'where' => "iid= '" . $iid . "'", // and sid=".$sid,
- 'asArray' => TRUE
- ) );
-
- $detail ['expressCompany'] = '';
- $detail ['expressCom'] = '';
- if (! empty ( $detail ['expressCompany'] )) {
- $express = explode ( ":", $detail ['expressCompany'] );
- $detail ['expressCompany'] = $express [0];
- $detail ['expressCom'] = $express [1];
- }
-
- $detail ['iidKeyXD'] = $this->authcode ( $detail ['iid'], '' );
-
- return $detail;
- }
-
- /**
- * 统计培训班开票
- */
- function sumOfinvoiceTrain($itidSql) {
- $sql = 'select sum(invoicePrice) as invoicePrice ,trainId
- from ' . $this->_table . '
- where trainId in (' . $itidSql . ') and status=2 and printStatus=1 and (untreadStatus =0 or untreadStatus=3)
- GROUP BY trainId';
- $query = Doo::db ()->query ( $sql );
- return $result = $query->fetchAll ();
- }
- function sumOfInvoiceRecelvablesTrain($itidSql) {
- $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
- from ' . $this->_table . ' as a left join CLD_invoiceReceivables as b on find_in_set(a.irid,b.irid)
- where a.trainId in (' . $itidSql . ') and a.status=2 and a.printStatus=1 and (a.untreadStatus =0 or a.untreadStatus=3) and a.irid!=""
- GROUP BY a.trainId';
- $query = Doo::db ()->query ( $sql );
- return $result = $query->fetchAll ();
- }
-
- /**
- * 根据仓库ID获得发票
- * @param string $Istoreid
- * @return unknown
- */
- public function getInvoiceByIstoreid($Istoreid = "", $select = "") {
- if (empty ( $Istoreid ))
- return array ();
-
- $condition = array (
- 'where' => "isid in ( " . $Istoreid . ")",
- 'asArray' => TRUE
- );
-
- if (! empty ( $select ))
- $condition += array (
- 'select' => $select
- );
-
- $detail = $this->find ( $condition );
-
- 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 and untreadStatus=0 ",
- '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;
- }
-
- /**
- * 根据参数字段批量更新相应字段(主键ID必须传)
- * @param array $item 相关需要更新的字段信息
- * @return number 返回发票ID
- */
- public function BatchInvoiceByCondition($item = array(), $iid = "") {
- $lid = 0;
-
- if (is_array ( $item ) && ! empty ( $item )) {
- foreach ( $item as $key => $value ) {
- $this->$key = $value;
- }
-
- if (! empty ( $iid )) {
- $condition = array (
- 'where' => "iid in (" . $iid . ")",
- 'asArray' => TRUE
- );
- $this->update ( $condition );
- } else
- $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 untreadStatus=0 and moldManage like '%[\"" . $sid . "\",%'",
- 'desc' => 'approvalTime',
- 'asArray' => TRUE
- ) );
- elseif (! empty ( $sid ) && ! empty ( $iid ))
- $list = $this->getOne ( array (
- 'where' => "status=2 and printStatus=" . $status . " and untreadStatus=0 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 and untreadStatus=0) or (status=2 and printStatus=0 and untreadStatus=0) or
- ( status=2 and printStatus=1 and untreadStatus=1 and untreadPost=0)
- or (postStatus=0 and doPost=1 and status=2 and untreadStatus=0) ) and isDelete=0 and sid=" . $sid,
- 'desc' => 'iid',
- 'asArray' => TRUE
- ) );
- foreach ( $list ['pendingInvoice'] as $key => $value ) {
- $list ['pendingInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
- $list ['pendingInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
- }
-
- $list ['handleInvoice'] = $this->find ( array (
- // 需求变更 -去除出票状态的数据 or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
- // 新加入退票中 需要邮寄的发票
- 'where' => "(status=3 or status=4 or (status=2 and untreadStatus=2 ) or ( status=2 and untreadStatus=1 ) ) 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 number $invoiceTC 发票title
- */
- public function getInvoiceByUnAccount($invoiceTC = '', $iridExist = false) {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
-
- $title = "";
- if (! empty ( $invoiceTC ))
- $title = ' and (invoiceTitle like "%' . $invoiceTC . '%" or invoiceCompany like "%' . $invoiceTC . '%" )';
-
- $iridString = ' and irid="" ';
- if ($iridExist)
- $iridString = ' and irid!="" ';
-
- $list = $this->find ( array ( //
- 'where' => "status=2 and printStatus=1 " . $iridString . " and untreadStatus=0 and ( (doPost=1 and postStatus=1) or doPost=0 ) and isDelete=0 " . $title,
- 'desc' => 'iid',
- 'limit' => 5,
- 'asArray' => TRUE
- ) );
- foreach ( $list as $key => $value ) {
- $list [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
- }
- return $list;
- }
-
- /**
- * 获得与我有关可收款的发票,已经出票的发票
- * @param number $sid 开票人ID
- */
- public function getInvoiceByReceivables($sid = 0) {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $list ['handleInvoice'] = $this->find ( array (
- 'where' => "(status=2 and printStatus=1 and untreadStatus=0 ) 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 ['handleInvoice'];
- }
-
- /**
- * 获取需要邮寄的发票
- * @param integer $postStatus 0为获取需要邮寄的发票,1为获取已经邮寄的发票
- * @return array|array() 返回相关数据
- */
- public function getPostByInvoice($postStatus = 0) {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $list = $this->find ( array ( // and untreadStatus=0
- 'where' => "postStatus=" . $postStatus . " and printStatus=1 and doPost=1 and status=2 and isDelete=0",
- 'limit' => 7,
- 'asArray' => TRUE
- ) );
- foreach ( $list as $key => $value ) {
- $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
- $list [$key] ['iidKeyK'] = $XDeode->encode ( $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) {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- if (empty ( $iid )) {
- $list = $this->find ( array ( // printStatus=1 and
- 'where' => " 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] ['iidKeyK'] = $XDeode->encode ( $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 );
- }
-
- $list [$key] ['lossDetail'] = array ();
- if ($value ['lossIid'] != 0) {
- $detail = $this->getOne ( array (
- 'where' => "iid=" . $value ['lossIid'],
- 'asArray' => TRUE
- ) );
- $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
- $list [$key] ['lossDetail'] = $detail;
- }
- }
- } else {
- $list = $this->getOne ( array (
- 'where' => "iid=" . $iid . " and printStatus=1 and untreadStatus=" . $untreadStatus . " and status=2",
- 'asArray' => TRUE
- ) );
- }
- return $list;
- }
- /**
- * 审批中获取相关数据 包括最近的一条操作记录
- * @param number $status.
- * @param number $limit.
- */
- function getInvoiceByProcessStatus($limit = 4, $desc = 'desc') {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $list = $this->find ( array (
- 'where' => " (status=1 or status=2 or status=3 or status=4) and processApprovals!=''",
- 'limit' => $limit,
- $desc => 'iid',
- 'asArray' => TRUE
- ) );
-
- Doo::loadModel ( 'invoiceOperationLog' );
- $invoiceOperationLog = new invoiceOperationLog ();
-
- foreach ( $list as $key => $value ) {
- $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
- $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], $value['status'] );
- }
-
- return $list;
- }
- function getInvoiceByUntreadStatusPage($limit = 0, $con = "", $desc = 'desc', $olStatus = "desc") {
- if (empty ( $limit ) || empty ( $con ))
- return array ();
-
- $listCount=$this->count(array (
- 'where' => $con,
- 'asArray' => TRUE
- ) ) ;
-
- $list = $this->find ( array (
- 'where' => $con,
- 'limit' => $limit,
- $desc => 'approvalTime',
- 'asArray' => TRUE
- ) );
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- Doo::loadModel ( 'invoiceReceivables' );
- $invoiceReceivables = new invoiceReceivables ();
- Doo::loadModel ( 'invoiceOperationLog' );
- $invoiceOperationLog = new invoiceOperationLog ();
-
- foreach ( $list as $key => $value ) {
- $list [$key] ['count'] = $listCount;
- $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
- $list [$key] ['iidKeyK'] = $XDeode->encode ( $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];
- }
-
- $list [$key] ['irList'] = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
-
- if ($olStatus == 'desc')
- $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
- else
- $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], $olStatus );
-
- $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
- $list [$key] ['OL'] = $invoiceOperationLog->getInvoiceOperationInStatus ( $value ['iid'], '2,3,4' );
-
- // print_r($list [$key] ['OperationLog']);
- $list [$key] ['sumPrice'] = 0;
- if (! empty ( $list [$key] ['irList'] ))
- $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
- // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
- $list [$key] ['lossDetail'] = array ();
- if ($value ['lossIid'] != 0) {
- $detail = $this->getOne ( array (
- 'where' => "iid=" . $value ['lossIid'],
- 'asArray' => TRUE
- ) );
- $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
- $list [$key] ['lossDetail'] = $detail;
- }
- $lossDate = strtotime ( "+1 month", strtotime ( $list [$key] ['OperationLog'] ['date'] ) );
- $nowDate = strtotime ( 'now' );
- $list [$key] ['lossShow'] = false;
- if ($lossDate < $nowDate)
- $list [$key] ['lossShow'] = 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 ) );
- }
- }
- }
- ?>
|