123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829 |
- <?php
- /**
- * @author darkredz
- */
- class ReceiptAjaxController extends DooController {
- public $staff;
- public $verifyId;
- public $executeId;
-
- // public static $NEW2 = 0;
- public $AGENCY = "日常相关费用";
- public $TRAVEL = "差旅相关费用";
- public $TRAIN = "培训班费用";
- public $OTHER = "其他";
- private $MYREVEIPTCACHEPATH = "protected/cache/myReceipt/";
- private $PERSONALCOLLECTCACHEPATH = "protected/cache/personalCollect/";
- private $CATEGORYCOLLECTPATH = "protected/cache/categoryCollect/";
- private $STAFFCOLLECTPATH = "protected/cache/staffCollect/";
-
- public function beforeRun($resource, $action) {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $sid = $XDeode->decode ( $_COOKIE ["staff"] );
- // 单独判断公司汇总的访问权限
- if ($action == 'companyCategoryCollect') {
- Doo::loadModel ( "receiptAuthorityManage" );
- $invoiceCompanyManage = new receiptAuthorityManage ();
-
- $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
- if (empty ( $icm ))
- die ( 'illegal request' );
- }
-
- Doo::loadModel ( 'staff' );
- $staff = new staff ();
- $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
-
- $accessModular = 'RECEIPTSAJAX';//是否已经开放的方法
- $accessAuthority = 'RECEIPTS';//容许访问的权限
- if (empty ( $detail ['cldAccessArray'] ))
- die ( 'illegal request' );
- else {
- if (in_array ( $accessAuthority, $detail ['cldAccessArray'] )) {
- if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
- $flag = true;
- } else {
- $flag = false;
- }
- } else {
- die ( 'illegal request' );
- }
- }
- if (! $flag)
- die ( 'illegal request' );
- }
- function __construct() {
- if (isset ( $_COOKIE ["staff"] )) {
-
- if (! empty ( $_COOKIE ["staff"] )) {
-
- Doo::loadModel ( 'staff' );
- Doo::loadModel ( 'verify' );
- $verify = new verify ();
- $staff = new staff ();
- Doo::loadModel ( "execute" );
- $execute = new execute ();
-
- $verifyList = $verify->find ( array (
- 'select' => 'staff',
- 'asArray' => true
- ) );
- $list = array ();
-
- // 判断角色的审批权限
- foreach ( $verifyList as $key => $value ) {
- $ver = json_decode ( $value ['staff'] );
-
- foreach ( $ver as $k => $v ) {
- if ($v [1] == 'ROLE') {
- $roleList = json_decode ( $v [3] );
- foreach ( $roleList as $t => $g ) {
- $gList = explode ( "_", $g );
- array_push ( $list, $gList [0] );
- // print_r($list);
- }
- } else
- array_push ( $list, $v [0] );
- }
- }
-
- // 判断执行人的审批权限
- $executeList = $execute->find ( array (
- 'select' => 'staff',
- 'asArray' => true
- ) );
- $list2 = array ();
- foreach ( $executeList as $key => $value ) {
- $ver = json_decode ( $value ['staff'] );
-
- foreach ( $ver as $k => $v ) {
- array_push ( $list2, $v [0] );
- }
- }
-
- $eidList = file_get_contents ( "protected/config/execute/execute.ini" );
- $eidList = array_filter ( explode ( ",", $eidList ) );
-
- $this->executeId = array_merge ( $list2, $eidList );
-
- $this->verifyId = $list;
- $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] )[0];
-
- // 检测用户信息完成
- $this->data ['isStaffCompleteMsg'] = false;
- $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
- if (! empty ( $detail ))
- $this->data ['isStaffCompleteMsg'] = true;
-
- return "/";
- }
- }
-
- Doo::loadCore ( 'uri/DooUriRouter' );
- $router = new DooUriRouter ();
- $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
-
- if ($routeRs ['1'] != "login") {
- header ( 'Content-Type:text/html;charset=utf-8' );
- @header ( "Location: /login" );
- }
- }
-
- function ajaxItineraryDate(){
- $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : '';
-
- Doo::loadClass ( 'receipt.func' );
- $falt=_verifyItineraryDate($date,$this->staff['sid']);
-
- echo json_encode ( array (
- 'status' => $falt
- ) );
- }
-
- /**
- * 默认获得属于自己和所在办事处10条最新的数据
- */
- function ajaxGetReceiptTrainLoan(){
- $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : $this->staff['sid'];
- $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
- $limit = $this->get_args ( 'limit' ) ? $this->get_args ( 'limit' ) : '30';
- $status=8;
- Doo::loadModel ( 'receipt' );
- $receipt = new receipt ();
-
- if(!empty($cid)){
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $cid = $XDeode->decode ( $cid );
- if(!is_numeric($cid)){
- $cid=$this->staff['cid'];
- }
- }
-
-
- $list=$receipt->getReceiptLoanByStatus($sid,$cid,$status,$limit);
-
- echo json_encode ( array (
- 'status' => 1,
- 'receiptLoanList' => $list
- ) );
- }
-
- /**
- * 获得费用详情
- */
- function ajaxGetReceiptDetailByJson() {
- $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
-
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $rid = $XDeode->decode ( $ridKey );
-
- Doo::loadModel ( 'receipt' );
- $receipt = new receipt ();
-
- $detail = $receipt->getReceiptByRid ( $rid );
-
-
- $payment=$this->_getReceiptTrainPayment($detail ['invoiceTrainId'],$detail ['trainLoanRid'],$rid);
-
-
- $detail['payment']=$payment;
- Doo::loadClass ( 'authcode.func' );
- $detail['paymentAuthCode']=authcode($payment,'');
-
- echo json_encode ( array (
- 'status' => 1,
- 'detail' => $detail
- ) );
- }
-
- function _getReceiptTrainPayment($invoiceTrainId,$trainLoanRid,$rid){
- // 收入合计
- Doo::loadModel ( 'invoiceTraining' );
- $invoiceTraining = new invoiceTraining ();
- Doo::loadModel ( 'receipt' );
- $receipt = new receipt ();
- $invoiceTrainingDetail = array (
- 'invoiceArriveAmount' => '0.00',
- 'RIAmount' => '0.00',
- 'invoiceTotalAmount' => '0.00',
- 'invoiceCompanyAmount' => '0.00',
- 'invoiceArriveAmountM'=>'0.00',
- 'invoiceCompanyAmountM'=>'0.00'
- );
- if ($invoiceTrainId != 0) {
- $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceTrainId );
- }
- $invoiceArriveAmount = $RIAmount = 0;
- if (! empty ( $invoiceTrainingDetail )) {
- $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
- $RIAmount = $invoiceTrainingDetail ['RIAmount'];
- }
-
- // 备用金
- $sum = 0;
- if (! empty ( $trainLoanRid )) {
- //$receiptLoanDetailBak = $receipt->getReceiptByRid ( $trainLoanRid );
- $receiptLoanList = $receipt->getReceiptInRid ( $trainLoanRid );
- foreach ($receiptLoanList as $key=>$value){
- $sum+=$value['sum'];
- }
- //$sum = $receiptLoanDetailBak ['sum'];
- }
-
- // 支出项金额详情
- // 项目金额合计
- Doo::loadModel ( 'RItem' );
- $RItem = new RItem ();
- Doo::loadModel ( 'accountItem' );
- $accountItem = new accountItem ();
- // 讲师获得
- Doo::loadModel ( 'RILecturer' );
- $RILecturer = new RILecturer ();
- $RItemList = $RItem->getRItemByRid ($rid );
- $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
- // 支出项金额详情
- $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
- $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
-
- $payment = $sum + $RIAmount - $categoryActualExpenditure;
- return $payment;
- }
-
- /**
- * 更新费用的汇款金额
- */
- function ajaxSetRceiptAmountByRid(){
- $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
- $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : '';
-
- if (empty($ridKey)||empty($amount)){
- echo json_encode ( array (
- 'status' => 2
- ) );
- die;
- }
-
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $rid = $XDeode->decode ( $ridKey );
- Doo::loadModel ( 'receipt' );
- $receipt = new receipt ();
- $detail=$receipt->getReceiptByRid($rid);
-
- if (empty($detail)){
- echo json_encode ( array (
- 'status' => 2
- ) );
- die;
- }
- if ($detail['status']!=2){
- echo json_encode ( array (
- 'status' => 2
- ) );
- die;
- }
- $receipt = new receipt ();
- $receipt->amount = $amount;
- $receipt->update ( array (
- 'where' => ' rid = ' . $rid
- ) );
- echo json_encode ( array (
- 'status' => 1
- ) );
- }
-
- /*
- * 流水报表数据
- */
- function ajaxWasteBookReportData(){
- Doo::loadModel ( 'wasteBook' );
- $wasteBook = new wasteBook ();
-
- $date = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
-
- if($date=='undefined'||empty($date)){
- $year=date('Y', strtotime(date("Y-m-d")));
- $month=date('m', strtotime(date("Y-m-d")));
- }else{
- $date=explode('-', $date);
- if(isset($date[1])){
- if(is_numeric ( $date[0] )&&is_numeric ( $date[1] )){
- $year=(int)$date[0];
- $month=(int)$date[1];
- }else{
- echo json_encode ( array ('msg' => 'is_numeric is error') );die;
- }
- }else{
- echo json_encode ( array ('msg' => 'date is error') );die;
- }
- }
-
- $days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
- $startYear=$year."-".$month."-01:00.00.00";
- $endYear=$year."-".$month."-".$days.":23.59.59";
-
- // $con = ' and year(inputDate) = "'.$year.'" and month(inputDate)="'.$month.'"';
- $con =' and inputDate>= "'.$startYear.'" and inputDate<="'.$endYear.'" ';
-
- //收入
- $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
- //支出
- $expenditureList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
-
- //print_r($incomeList);
-
- $firstday = date('Y-m-01', strtotime(date("Y-m-d")));
- // $lastday = date('d', strtotime("$firstday +1 month -1 day"));
- $lastday = $days;
-
- //print_r($incomeList);
- //导入流水func
- Doo::loadClass ( 'receipt.finances.func' );
-
- //1-0获得这月之前的所有金额合计
- include './protected/config/wasteBook.conf.php';
- $balance=$wbBalance;
- $balanceSum=$wasteBook->getStatisticsByMonthAll($year,$month);
- if(!empty($balanceSum[0]['accountPrice'])){
- $balance+=$balanceSum[0]['accountPrice'];
- }
-
- $data=array();
- //1-1 日排序
- for($day=$lastday;$day>0;$day--){
- $data[$year.'-'.str_pad($month,2,'0',STR_PAD_LEFT).'-'.str_pad($day,2,'0',STR_PAD_LEFT)]=array();
- }
-
- //1-2 设置流水收入
- foreach ($incomeList as $key=>$value){
-
- $inputDate=date('Y-m-d', strtotime($value['inputDate']));
- $item['inputDate']=$inputDate;
-
- //TODO-收款和日常收入-付款单位
- $item['receivablesMessage']='';
- if($value['accountType']==5||$value['accountType']==6){
- $item['receivablesMessage']=$value['data']['remarks'];
- }elseif($value['accountType']==7){
- $item['receivablesMessage']=$value['data']['receivablesMessage'];
- }
-
- //类型
- $item['revenueType']='';
- if($value['expensesType']==1){
- $item['revenueType']=_getRevenueTypeCN($value);
- }
-
- $item['category']=$value['category'];
-
- //结算方式--只有发票和收款才有
- $item['settlementType']='';
- if($value['accountType']==8||$value['accountType']==7){
- if(isset($value['data']['settlementType'])){
- $item['settlementType']='软件销售';
- if($value['data']['settlementType']==1){
- $item['settlementType']='培训班';
- }
- }
-
- }
-
- $item['revenueBankMsg']=$value['accountBankMsg'];
- $item['revenuePriceShow']=$value['accountPriceShow'];
- $item['revenueTotalDay']='';
- //echo $inputDate.'</br>';
- array_push($data[$inputDate], $item);
- }
- //print_r($incomeList);
- //组合支出
- //1-3设置支出
- $bakDate=0;
- foreach ($expenditureList as $key=>$value){
- $inputDate=date('Y-m-d', strtotime($value['inputDate']));
-
- if($bakDate!=$inputDate){
- $bakDate=$inputDate;
- $index=0;
- }
-
- if(isset($data[$inputDate][$index])){
-
- //费用类别
- $item['outlayType']=_getOutlayTypeCN($value);
- //支出内容
- $item['outlayMsg']=' /'.$value['category'];
- if($value['accountType']==5||$value['accountType']==9||$value['accountType']==10){
- $item['outlayMsg']=$value['data']['remarks'];
- }
-
- $item['outlayBankMsg']=$value['accountBankMsg'];
- $item['outlayPriceShow']=$value['accountPriceShow'];
-
- $data[$inputDate][$index]+=$item;
-
- }else{
- $item['inputDate']=$inputDate;
- $item['receivablesMessage']='';
- $item['revenueType']='';
- $item['category']='';
- $item['settlementType']='';
- $item['revenueBankMsg']='';
- $item['revenuePriceShow']='';
-
- //支出项
- //费用类别
- $item['outlayType']=_getOutlayTypeCN($value);
- //支出内容
- $item['outlayMsg']='/'.$value['category'];
- $item['outlayBankMsg']=$value['accountBankMsg'];
- $item['outlayPriceShow']=$value['accountPriceShow'];
- $item['outlayTotalDay']='';
- array_push($data[$inputDate], $item);
- }
- $index++;
- }
-
- //TODO 1-4 计算每日合计
- $revenueTotalMonthPrice=$outlayTotalMonthPrice=0;
- foreach ($data as $key=>$value){
- if(!empty($value)){
- $revenueTotalDayPrice=$outlayTotalDayPrice=0;
- foreach ($value as $v){
- if(isset($v['revenuePriceShow'])){
- $revenueTotalDayPrice+=$v['revenuePriceShow'];
- $revenueTotalMonthPrice+=$v['revenuePriceShow'];
- }
- if(isset($v['outlayPriceShow'])){
- $outlayTotalDayPrice+=$v['outlayPriceShow'];
- $outlayTotalMonthPrice+=$v['outlayPriceShow'];
- }
- }
- $item=_structureReportItem('','','','','','','今日总收入',number_format($revenueTotalDayPrice,2)
- ,'','','','今日总支出',number_format($outlayTotalDayPrice,2));
- $item['balance']=bcadd($balance,$revenueTotalDayPrice-$outlayTotalDayPrice,2);
- array_push($data[$key], $item);
- }
- }
-
-
- $pieDetailData=array();
- foreach ($data as $key=>$value){
- //$pieDetailData[$key]=array();
- $revenueTotalDay=$outlayTotalDay=0;
- if(!empty($value)){
- $item=end($value);
- if (isset($item['revenueTotalDay'])){
- $revenueTotalDay=str_replace(',','',$item['revenueTotalDay']);
- }
- if(isset($item['revenueTotalDay'])){
- $outlayTotalDay=str_replace(',','',$item['outlayTotalDay']);
- }
- }
- if($revenueTotalDay!=0&&$outlayTotalDay!=0){
- $pieDetailData[$key]=array($revenueTotalDay,$outlayTotalDay);
- }
-
- //array_push($pieDetailData[$key], array($revenueTotalDay,$outlayTotalDay));
- }
- //print_r($pieDetailData);
-
- //格式化数据
-
- $item=_structureReportItem('月初金额','','','','','','',0
- ,'','','','',0);
- $item['key']='balance';
- $item['balance']=$balance;
- $jsonList[0]= $item;
-
- $item=_structureReportItem('','','','','','','总收入',number_format($revenueTotalMonthPrice,2)
- ,'','','','总支出',number_format($outlayTotalMonthPrice,2));
- $item['balance']=bcadd($balance,$revenueTotalMonthPrice-$outlayTotalMonthPrice,2);
- $item['key']='summary';
- $jsonList[1]= $item;
-
- //$jsonList=array();
- $dayList=array();
- foreach ($data as $key=>$value){
- foreach ($value as $k=>$v){
- $v['key']=$k;
- array_push($jsonList, $v);
- array_push($dayList, $key);
- }
- }
- //echo $firstday;
- //print_r($incomeList);
-
- // $item=_structureReportItem('','','','','','','总收入',number_format($revenueTotalMonthPrice,2)
- // ,'','','','总支出',number_format($outlayTotalMonthPrice,2));
- // $item['balance']=$balance+$revenueTotalMonthPrice-$outlayTotalMonthPrice;
- // $item['key']='summary';
- // array_push($jsonList, $item);
-
- //日期筛选数据
- $dayList=array_unique($dayList);
- $list=array();
- foreach ($dayList as $value){
- array_push($list, array('text'=>$value,'value'=>$value));
- }
- //print_r(array_values($dayList));
-
- echo json_encode ( array (
- 'reportData' => $jsonList,
- 'reportDay'=>$list,
- 'reportDateStart'=>$year.'-'.str_pad(($month),2,"0",STR_PAD_LEFT),
- 'reportDateEnd'=>$year.'-'.str_pad(($month+1),2,"0",STR_PAD_LEFT),
- 'pieDetailData'=>$pieDetailData,
- ) );
-
- //echo json_encode($jsonList);
-
- }
-
- function setWXMsg($rid, $type) {
- Doo::loadModel ( "receipt" );
- $receipt = new receipt ();
- $receiptDetail = $receipt->getOne ( array (
- 'where' => 'rid=' . $rid,
- 'asArray' => true
- ) );
- if (! empty ( $receiptDetail )) {
- Doo::loadModel ( 'staff' );
- $staff = new staff ();
- $staffmsg = $staff->getOne ( array (
- 'where' => "sid='" . $receiptDetail ['staff'] . "'",
- 'asArray' => TRUE
- ) );
- if (! empty ( $staffmsg ['wxid'] )) {
- require_once (SITE_PATH . '/protected/class/client.php');
- $client = new client ( 'http://m.cld.smartcost.com.cn/' );
- $user = $staffmsg ['wxid'];
- $receiptName = '';
- $msg = '';
- switch ($receiptDetail ['Rtype']) {
- case 0 :
- $receiptName = '报销';
- break;
- case 1 :
- $receiptName = '借款';
- break;
- case 2 :
- $receiptName = '对公汇款';
- break;
- }
- switch ($type) {
- case 1 :
- $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
- break;
- case 2 :
- $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
- break;
- case 3 :
- $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
- break;
- }
-
- // $result = $client->SendMsg ( $user, $msg, 'text' );
- }
- }
- }
-
- // Email发送函数
- function SMail($toemail, $subject, $contents) {
- Doo::loadClass ( 'class.phpmailer' );
- $mail = new PHPMailer ();
- $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
- $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
- $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
- $mail->Password = "cDO1GjtY1seH"; // 密码
- $mail->CharSet = "UTF8";
- $mail->SMTPAuth = true;
- $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
- $mail->Mailer = "smtp";
- $mail->Port = 25;
- $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
- $mail->MsgHTML ( $contents );
- $mail->AddAddress ( $toemail );
- $mail->CharSet = "UTF-8";
- return $mail->Send ();
- }
- function swfupload() {
- $POST_MAX_SIZE = ini_get ( 'post_max_size' );
- $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
- $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
-
- if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
- header ( "HTTP/1.1 500 Internal Server Error" );
- echo "POST exceeded maximum allowed size.";
- exit ( 0 );
- }
-
- // Settings
- $save_path = DOO::conf ()->SITE_PATH . "upload/swfupload/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
- $upload_name = "Filedata";
- $max_file_size_in_bytes = 2147483647; // 2GB in bytes
- $extension_whitelist = array (
- "doc",
- "txt",
- "jpg",
- "gif",
- "png"
- ); // Allowed file extensions
- $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
-
- // Other variables
- $MAX_FILENAME_LENGTH = 260;
- $file_name = "";
- $file_extension = "";
- $uploadErrors = array (
- 0 => "文件上传成功",
- 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
- 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
- 3 => "上传的文件仅为部分文件",
- 4 => "没有文件上传",
- 6 => "缺少临时文件夹"
- );
-
- $nk = time ();
- $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
-
- if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
- echo "文件无法保存.";
- exit ( 0 );
- }
-
- // Return output to the browser (only supported by SWFUpload for Flash Player 9)
-
- echo json_encode ( array (
- 'filename' => $file_name,
- 'id' => $nk
- ) );
- exit ( 0 );
- }
- function _GetFileEXT($filename) {
- $pics = explode ( '.', $filename );
-
- $num = count ( $pics );
-
- return $pics [$num - 1];
- }
-
- /**
- * 获取get或者POST值
- * @param string $name 属性名称
- * @return fixed 值
- */
- function get_args($name) {
- if (isset ( $_GET [$name] )) {
- if (is_array ( $_GET [$name] ))
- return $_GET [$name];
- else
- return addslashes ( $_GET [$name] );
- } elseif (isset ( $_POST [$name] )) {
- if (is_array ( $_POST [$name] ))
- return $_POST [$name];
- else
- return addslashes ( $_POST [$name] );
- } else
- return false;
- }
- function num_to_rmb($num) {
- $c1 = "零壹贰叁肆伍陆柒捌玖";
- $c2 = "分角元拾佰仟万拾佰仟亿";
- // 精确到分后面就不要了,所以只留两个小数位
- $num = round ( $num, 2 );
- // 将数字转化为整数
- $num = $num * 100;
- if (strlen ( $num ) > 10) {
- return "金额太大,请检查";
- }
- $i = 0;
- $c = "";
- while ( 1 ) {
- if ($i == 0) {
- // 获取最后一位数字
- $n = substr ( $num, strlen ( $num ) - 1, 1 );
- } else {
- $n = $num % 10;
- }
- // 每次将最后一位数字转化为中文
- $p1 = substr ( $c1, 3 * $n, 3 );
- $p2 = substr ( $c2, 3 * $i, 3 );
-
- if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
- $c = $p1 . $p2 . $c;
- } else {
- $c = $p1 . $c;
- }
- $i = $i + 1;
- // 去掉数字最后一位了
-
- $num = $num / 10;
- // echo $num.'</br>';
- $num = ( int ) $num;
- // $num =floor($num);
- // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
- // echo $num.'</br>';
- // 结束循环
- if ($num == 0) {
- break;
- }
- }
- // echo $c.'</br>';
- $j = 0;
- $slen = strlen ( $c );
- while ( $j < $slen ) {
- // utf8一个汉字相当3个字符
- $m = substr ( $c, $j, 6 );
- // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
- if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
- $left = substr ( $c, 0, $j );
- $right = substr ( $c, $j + 3 );
- $c = $left . $right;
- $j = $j - 3;
- $slen = $slen - 3;
- }
- $j = $j + 3;
- }
- // 这个是为了去掉类似23.0中最后一个“零”字
- if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
- $c = substr ( $c, 0, strlen ( $c ) - 3 );
- }
- // 将处理的汉字加上“整”
- if (empty ( $c )) {
- return "零元整";
- } else {
- return $c . "整";
- }
- }
-
- /**
- * 获得分页数据
- * @param unknown_type $table
- * @param unknown_type $condition
- * @param unknown_type $on_page
- * @param unknown_type $page_size
- */
- function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
- $page_c = "";
- $page ['previous'] = $this->get_previous ( $on_page );
- $page ['on_page'] = $on_page;
- $total_count = $this->get_table_count ( $table, $condition );
- $total = intval ( $total_count / $page_size );
-
- $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
- $page ['total_data'] = $total_count;
- $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
-
- $i = 1;
- $page_max = 1;
- $page_width = 3;
-
- if ($on_page >= $page_width) {
- $page_max = intval ( $on_page / $page_width ) + 1;
- $i = intval ( $on_page / $page_width ) * $page_width - 1;
- }
-
- for(; $i <= $page ['total_page']; $i ++) {
- if ($i == $on_page)
- $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
- else
- $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
-
- if ($i == ($page_width * $page_max))
- break;
- }
-
- $page ['page'] = $page_c;
- $page ['lower'] = (-- $on_page) * $page_size;
- return $page;
- }
-
- /**
- * 获取总页数
- * @param unknown_type $table
- * @param unknown_type $condition
- */
- public function get_table_count($table = "", $condition = "") {
- // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
- $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
-
- // echo $sql;die;
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetch ();
- return $result ['count'];
- }
- /**
- * 获取上一页
- * @param unknown_type $on_page
- */
- function get_previous($on_page = 1) {
- return $on_page != 0 ? $on_page - 1 : $on_page;
- }
- }
- ?>
|