ReceiptAjaxController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptAjaxController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. // public static $NEW2 = 0;
  10. public $AGENCY = "日常相关费用";
  11. public $TRAVEL = "差旅相关费用";
  12. public $TRAIN = "培训班费用";
  13. public $OTHER = "其他";
  14. private $MYREVEIPTCACHEPATH = "protected/cache/myReceipt/";
  15. private $PERSONALCOLLECTCACHEPATH = "protected/cache/personalCollect/";
  16. private $CATEGORYCOLLECTPATH = "protected/cache/categoryCollect/";
  17. private $STAFFCOLLECTPATH = "protected/cache/staffCollect/";
  18. public function beforeRun($resource, $action) {
  19. Doo::loadClass ( 'XDeode' );
  20. $XDeode = new XDeode ( 5 );
  21. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  22. // 单独判断公司汇总的访问权限
  23. if ($action == 'companyCategoryCollect') {
  24. Doo::loadModel ( "receiptAuthorityManage" );
  25. $invoiceCompanyManage = new receiptAuthorityManage ();
  26. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  27. if (empty ( $icm ))
  28. die ( 'illegal request' );
  29. }
  30. Doo::loadModel ( 'staff' );
  31. $staff = new staff ();
  32. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  33. $accessModular = 'RECEIPTSAJAX';//是否已经开放的方法
  34. $accessAuthority = 'RECEIPTS';//容许访问的权限
  35. if (empty ( $detail ['cldAccessArray'] ))
  36. die ( 'illegal request' );
  37. else {
  38. if (in_array ( $accessAuthority, $detail ['cldAccessArray'] )) {
  39. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  40. $flag = true;
  41. } else {
  42. $flag = false;
  43. }
  44. } else {
  45. die ( 'illegal request' );
  46. }
  47. }
  48. if (! $flag)
  49. die ( 'illegal request' );
  50. }
  51. function __construct() {
  52. if (isset ( $_COOKIE ["staff"] )) {
  53. if (! empty ( $_COOKIE ["staff"] )) {
  54. Doo::loadModel ( 'staff' );
  55. Doo::loadModel ( 'verify' );
  56. $verify = new verify ();
  57. $staff = new staff ();
  58. Doo::loadModel ( "execute" );
  59. $execute = new execute ();
  60. $verifyList = $verify->find ( array (
  61. 'select' => 'staff',
  62. 'asArray' => true
  63. ) );
  64. $list = array ();
  65. // 判断角色的审批权限
  66. foreach ( $verifyList as $key => $value ) {
  67. $ver = json_decode ( $value ['staff'] );
  68. foreach ( $ver as $k => $v ) {
  69. if ($v [1] == 'ROLE') {
  70. $roleList = json_decode ( $v [3] );
  71. foreach ( $roleList as $t => $g ) {
  72. $gList = explode ( "_", $g );
  73. array_push ( $list, $gList [0] );
  74. // print_r($list);
  75. }
  76. } else
  77. array_push ( $list, $v [0] );
  78. }
  79. }
  80. // 判断执行人的审批权限
  81. $executeList = $execute->find ( array (
  82. 'select' => 'staff',
  83. 'asArray' => true
  84. ) );
  85. $list2 = array ();
  86. foreach ( $executeList as $key => $value ) {
  87. $ver = json_decode ( $value ['staff'] );
  88. foreach ( $ver as $k => $v ) {
  89. array_push ( $list2, $v [0] );
  90. }
  91. }
  92. $eidList = file_get_contents ( "protected/config/execute/execute.ini" );
  93. $eidList = array_filter ( explode ( ",", $eidList ) );
  94. $this->executeId = array_merge ( $list2, $eidList );
  95. $this->verifyId = $list;
  96. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] )[0];
  97. // 检测用户信息完成
  98. $this->data ['isStaffCompleteMsg'] = false;
  99. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  100. if (! empty ( $detail ))
  101. $this->data ['isStaffCompleteMsg'] = true;
  102. return "/";
  103. }
  104. }
  105. Doo::loadCore ( 'uri/DooUriRouter' );
  106. $router = new DooUriRouter ();
  107. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  108. if ($routeRs ['1'] != "login") {
  109. header ( 'Content-Type:text/html;charset=utf-8' );
  110. @header ( "Location: /login" );
  111. }
  112. }
  113. function ajaxItineraryDate(){
  114. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : '';
  115. Doo::loadClass ( 'receipt.func' );
  116. $falt=_verifyItineraryDate($date,$this->staff['sid']);
  117. echo json_encode ( array (
  118. 'status' => $falt
  119. ) );
  120. }
  121. /**
  122. * 默认获得属于自己和所在办事处10条最新的数据
  123. */
  124. function ajaxGetReceiptTrainLoan(){
  125. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : $this->staff['sid'];
  126. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  127. $limit = $this->get_args ( 'limit' ) ? $this->get_args ( 'limit' ) : '30';
  128. $status=8;
  129. Doo::loadModel ( 'receipt' );
  130. $receipt = new receipt ();
  131. if(!empty($cid)){
  132. Doo::loadClass ( 'XDeode' );
  133. $XDeode = new XDeode ( 5 );
  134. $cid = $XDeode->decode ( $cid );
  135. if(!is_numeric($cid)){
  136. $cid=$this->staff['cid'];
  137. }
  138. }
  139. $list=$receipt->getReceiptLoanByStatus($sid,$cid,$status,$limit);
  140. echo json_encode ( array (
  141. 'status' => 1,
  142. 'receiptLoanList' => $list
  143. ) );
  144. }
  145. /**
  146. * 获得费用详情
  147. */
  148. function ajaxGetReceiptDetailByJson() {
  149. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  150. Doo::loadClass ( 'XDeode' );
  151. $XDeode = new XDeode ( 5 );
  152. $rid = $XDeode->decode ( $ridKey );
  153. Doo::loadModel ( 'receipt' );
  154. $receipt = new receipt ();
  155. $detail = $receipt->getReceiptByRid ( $rid );
  156. $payment=$this->_getReceiptTrainPayment($detail ['invoiceTrainId'],$detail ['trainLoanRid'],$rid);
  157. $detail['payment']=$payment;
  158. Doo::loadClass ( 'authcode.func' );
  159. $detail['paymentAuthCode']=authcode($payment,'');
  160. echo json_encode ( array (
  161. 'status' => 1,
  162. 'detail' => $detail
  163. ) );
  164. }
  165. function _getReceiptTrainPayment($invoiceTrainId,$trainLoanRid,$rid){
  166. // 收入合计
  167. Doo::loadModel ( 'invoiceTraining' );
  168. $invoiceTraining = new invoiceTraining ();
  169. Doo::loadModel ( 'receipt' );
  170. $receipt = new receipt ();
  171. $invoiceTrainingDetail = array (
  172. 'invoiceArriveAmount' => '0.00',
  173. 'RIAmount' => '0.00',
  174. 'invoiceTotalAmount' => '0.00',
  175. 'invoiceCompanyAmount' => '0.00',
  176. 'invoiceArriveAmountM'=>'0.00',
  177. 'invoiceCompanyAmountM'=>'0.00'
  178. );
  179. if ($invoiceTrainId != 0) {
  180. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceTrainId );
  181. }
  182. $invoiceArriveAmount = $RIAmount = 0;
  183. if (! empty ( $invoiceTrainingDetail )) {
  184. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  185. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  186. }
  187. // 备用金
  188. $sum = 0;
  189. if (! empty ( $trainLoanRid )) {
  190. //$receiptLoanDetailBak = $receipt->getReceiptByRid ( $trainLoanRid );
  191. $receiptLoanList = $receipt->getReceiptInRid ( $trainLoanRid );
  192. foreach ($receiptLoanList as $key=>$value){
  193. $sum+=$value['sum'];
  194. }
  195. //$sum = $receiptLoanDetailBak ['sum'];
  196. }
  197. // 支出项金额详情
  198. // 项目金额合计
  199. Doo::loadModel ( 'RItem' );
  200. $RItem = new RItem ();
  201. Doo::loadModel ( 'accountItem' );
  202. $accountItem = new accountItem ();
  203. // 讲师获得
  204. Doo::loadModel ( 'RILecturer' );
  205. $RILecturer = new RILecturer ();
  206. $RItemList = $RItem->getRItemByRid ($rid );
  207. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  208. // 支出项金额详情
  209. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  210. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  211. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  212. return $payment;
  213. }
  214. /**
  215. * 更新费用的汇款金额
  216. */
  217. function ajaxSetRceiptAmountByRid(){
  218. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  219. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : '';
  220. if (empty($ridKey)||empty($amount)){
  221. echo json_encode ( array (
  222. 'status' => 2
  223. ) );
  224. die;
  225. }
  226. Doo::loadClass ( 'XDeode' );
  227. $XDeode = new XDeode ( 5 );
  228. $rid = $XDeode->decode ( $ridKey );
  229. Doo::loadModel ( 'receipt' );
  230. $receipt = new receipt ();
  231. $detail=$receipt->getReceiptByRid($rid);
  232. if (empty($detail)){
  233. echo json_encode ( array (
  234. 'status' => 2
  235. ) );
  236. die;
  237. }
  238. if ($detail['status']!=2){
  239. echo json_encode ( array (
  240. 'status' => 2
  241. ) );
  242. die;
  243. }
  244. $receipt = new receipt ();
  245. $receipt->amount = $amount;
  246. $receipt->update ( array (
  247. 'where' => ' rid = ' . $rid
  248. ) );
  249. echo json_encode ( array (
  250. 'status' => 1
  251. ) );
  252. }
  253. /*
  254. * 流水报表数据
  255. */
  256. function ajaxWasteBookReportData(){
  257. Doo::loadModel ( 'wasteBook' );
  258. $wasteBook = new wasteBook ();
  259. $date = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
  260. if($date=='undefined'||empty($date)){
  261. $year=date('Y', strtotime(date("Y-m-d")));
  262. $month=date('m', strtotime(date("Y-m-d")));
  263. }else{
  264. $date=explode('-', $date);
  265. if(isset($date[1])){
  266. if(is_numeric ( $date[0] )&&is_numeric ( $date[1] )){
  267. $year=(int)$date[0];
  268. $month=(int)$date[1];
  269. }else{
  270. echo json_encode ( array ('msg' => 'is_numeric is error') );die;
  271. }
  272. }else{
  273. echo json_encode ( array ('msg' => 'date is error') );die;
  274. }
  275. }
  276. $con = ' and year(inputDate) = "'.$year.'" and month(inputDate)="'.$month.'"';
  277. //收入
  278. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  279. //支出
  280. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  281. $firstday = date('Y-m-01', strtotime(date("Y-m-d")));
  282. $lastday = date('d', strtotime("$firstday +1 month -1 day"));
  283. //print_r($incomeList);
  284. //导入流水func
  285. Doo::loadClass ( 'receipt.finances.func' );
  286. //1-0获得这月之前的所有金额合计
  287. include './protected/config/wasteBook.conf.php';
  288. $balance=$wbBalance;
  289. $balanceSum=$wasteBook->getStatisticsByMonthAll($year,$month);
  290. if(!empty($balanceSum[0]['accountPrice'])){
  291. $balance+=$balanceSum[0]['accountPrice'];
  292. }
  293. $data=array();
  294. //1-1 日排序
  295. for($day=$lastday;$day>0;$day--){
  296. $data[$year.'-'.str_pad($month,2,'0',STR_PAD_LEFT).'-'.str_pad($day,2,'0',STR_PAD_LEFT)]=array();
  297. }
  298. //1-2 设置流水收入
  299. foreach ($incomeList as $key=>$value){
  300. $inputDate=date('Y-m-d', strtotime($value['inputDate']));
  301. $item['inputDate']=$inputDate;
  302. //TODO-收款和日常收入-付款单位
  303. $item['receivablesMessage']='';
  304. if($value['accountType']==5||$value['accountType']==6){
  305. $item['receivablesMessage']=$value['data']['remarks'];
  306. }elseif($value['accountType']==7){
  307. $item['receivablesMessage']=$value['data']['receivablesMessage'];
  308. }
  309. //类型
  310. $item['revenueType']='';
  311. if($value['expensesType']==1){
  312. $item['revenueType']=_getRevenueTypeCN($value);
  313. }
  314. $item['category']=$value['category'];
  315. //结算方式--只有发票和收款才有
  316. $item['settlementType']='';
  317. if($value['accountType']==8||$value['accountType']==7){
  318. if(isset($value['data']['settlementType'])){
  319. $item['settlementType']='软件销售';
  320. if($value['data']['settlementType']==1){
  321. $item['settlementType']='培训班';
  322. }
  323. }
  324. }
  325. $item['revenueBankMsg']=$value['accountBankMsg'];
  326. $item['revenuePriceShow']=$value['accountPriceShow'];
  327. $item['revenueTotalDay']='';
  328. //echo $inputDate.'</br>';
  329. array_push($data[$inputDate], $item);
  330. }
  331. //print_r($incomeList);
  332. //组合支出
  333. //1-3设置支出
  334. $bakDate=0;
  335. foreach ($expenditureList as $key=>$value){
  336. $inputDate=date('Y-m-d', strtotime($value['inputDate']));
  337. if($bakDate!=$inputDate){
  338. $bakDate=$inputDate;
  339. $index=0;
  340. }
  341. if(isset($data[$inputDate][$index])){
  342. //费用类别
  343. $item['outlayType']=_getOutlayTypeCN($value);
  344. //支出内容
  345. $item['outlayMsg']='';
  346. if($value['accountType']==5||$value['accountType']==9||$value['accountType']==10){
  347. $item['outlayMsg']=$value['data']['remarks'];
  348. }
  349. $item['outlayBankMsg']=$value['accountBankMsg'];
  350. $item['outlayPriceShow']=$value['accountPriceShow'];
  351. $data[$inputDate][$index]+=$item;
  352. }else{
  353. $item['inputDate']=$inputDate;
  354. $item['receivablesMessage']='';
  355. $item['revenueType']='';
  356. $item['category']='';
  357. $item['settlementType']='';
  358. $item['revenueBankMsg']='';
  359. $item['revenuePriceShow']='';
  360. //支出项
  361. //费用类别
  362. $item['outlayType']=_getOutlayTypeCN($value);
  363. //支出内容
  364. $item['outlayMsg']='';
  365. $item['outlayBankMsg']=$value['accountBankMsg'];
  366. $item['outlayPriceShow']=$value['accountPriceShow'];
  367. $item['outlayTotalDay']='';
  368. array_push($data[$inputDate], $item);
  369. }
  370. $index++;
  371. }
  372. //TODO 1-4 计算每日合计
  373. $revenueTotalMonthPrice=$outlayTotalMonthPrice=0;
  374. foreach ($data as $key=>$value){
  375. if(!empty($value)){
  376. $revenueTotalDayPrice=$outlayTotalDayPrice=0;
  377. foreach ($value as $v){
  378. if(isset($v['revenuePriceShow'])){
  379. $revenueTotalDayPrice+=$v['revenuePriceShow'];
  380. $revenueTotalMonthPrice+=$v['revenuePriceShow'];
  381. }
  382. if(isset($v['outlayPriceShow'])){
  383. $outlayTotalDayPrice+=$v['outlayPriceShow'];
  384. $outlayTotalMonthPrice+=$v['outlayPriceShow'];
  385. }
  386. }
  387. $item=_structureReportItem('','','','','','','今日总收入',number_format($revenueTotalDayPrice,2)
  388. ,'','','','今日总支出',number_format($outlayTotalDayPrice,2));
  389. $item['balance']=$balance+$revenueTotalDayPrice-$outlayTotalDayPrice;
  390. array_push($data[$key], $item);
  391. }
  392. }
  393. $pieDetailData=array();
  394. foreach ($data as $key=>$value){
  395. //$pieDetailData[$key]=array();
  396. $revenueTotalDay=$outlayTotalDay=0;
  397. if(!empty($value)){
  398. $item=end($value);
  399. if (isset($item['revenueTotalDay'])){
  400. $revenueTotalDay=str_replace(',','',$item['revenueTotalDay']);
  401. }
  402. if(isset($item['revenueTotalDay'])){
  403. $outlayTotalDay=str_replace(',','',$item['outlayTotalDay']);
  404. }
  405. }
  406. if($revenueTotalDay!=0&&$outlayTotalDay!=0){
  407. $pieDetailData[$key]=array($revenueTotalDay,$outlayTotalDay);
  408. }
  409. //array_push($pieDetailData[$key], array($revenueTotalDay,$outlayTotalDay));
  410. }
  411. //print_r($pieDetailData);
  412. //格式化数据
  413. $item=_structureReportItem('月初金额','','','','','','',0
  414. ,'','','','',0);
  415. $item['key']='balance';
  416. $item['balance']=$balance;
  417. $jsonList[0]= $item;
  418. $item=_structureReportItem('','','','','','','总收入',number_format($revenueTotalMonthPrice,2)
  419. ,'','','','总支出',number_format($outlayTotalMonthPrice,2));
  420. $item['balance']=$balance+$revenueTotalMonthPrice-$outlayTotalMonthPrice;
  421. $item['key']='summary';
  422. $jsonList[1]= $item;
  423. //$jsonList=array();
  424. $dayList=array();
  425. foreach ($data as $key=>$value){
  426. foreach ($value as $k=>$v){
  427. $v['key']=$k;
  428. array_push($jsonList, $v);
  429. array_push($dayList, $key);
  430. }
  431. }
  432. //echo $firstday;
  433. //print_r($incomeList);
  434. // $item=_structureReportItem('','','','','','','总收入',number_format($revenueTotalMonthPrice,2)
  435. // ,'','','','总支出',number_format($outlayTotalMonthPrice,2));
  436. // $item['balance']=$balance+$revenueTotalMonthPrice-$outlayTotalMonthPrice;
  437. // $item['key']='summary';
  438. // array_push($jsonList, $item);
  439. //日期筛选数据
  440. $dayList=array_unique($dayList);
  441. $list=array();
  442. foreach ($dayList as $value){
  443. array_push($list, array('text'=>$value,'value'=>$value));
  444. }
  445. //print_r(array_values($dayList));
  446. echo json_encode ( array (
  447. 'reportData' => $jsonList,
  448. 'reportDay'=>$list,
  449. 'reportDateStart'=>$year.'-'.str_pad(($month),2,"0",STR_PAD_LEFT),
  450. 'reportDateEnd'=>$year.'-'.str_pad(($month+1),2,"0",STR_PAD_LEFT),
  451. 'pieDetailData'=>$pieDetailData,
  452. ) );
  453. //echo json_encode($jsonList);
  454. }
  455. function setWXMsg($rid, $type) {
  456. Doo::loadModel ( "receipt" );
  457. $receipt = new receipt ();
  458. $receiptDetail = $receipt->getOne ( array (
  459. 'where' => 'rid=' . $rid,
  460. 'asArray' => true
  461. ) );
  462. if (! empty ( $receiptDetail )) {
  463. Doo::loadModel ( 'staff' );
  464. $staff = new staff ();
  465. $staffmsg = $staff->getOne ( array (
  466. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  467. 'asArray' => TRUE
  468. ) );
  469. if (! empty ( $staffmsg ['wxid'] )) {
  470. require_once (SITE_PATH . '/protected/class/client.php');
  471. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  472. $user = $staffmsg ['wxid'];
  473. $receiptName = '';
  474. $msg = '';
  475. switch ($receiptDetail ['Rtype']) {
  476. case 0 :
  477. $receiptName = '报销';
  478. break;
  479. case 1 :
  480. $receiptName = '借款';
  481. break;
  482. case 2 :
  483. $receiptName = '对公汇款';
  484. break;
  485. }
  486. switch ($type) {
  487. case 1 :
  488. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  489. break;
  490. case 2 :
  491. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  492. break;
  493. case 3 :
  494. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  495. break;
  496. }
  497. // $result = $client->SendMsg ( $user, $msg, 'text' );
  498. }
  499. }
  500. }
  501. // Email发送函数
  502. function SMail($toemail, $subject, $contents) {
  503. Doo::loadClass ( 'class.phpmailer' );
  504. $mail = new PHPMailer ();
  505. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  506. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  507. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  508. $mail->Password = "cDO1GjtY1seH"; // 密码
  509. $mail->CharSet = "UTF8";
  510. $mail->SMTPAuth = true;
  511. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  512. $mail->Mailer = "smtp";
  513. $mail->Port = 25;
  514. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  515. $mail->MsgHTML ( $contents );
  516. $mail->AddAddress ( $toemail );
  517. $mail->CharSet = "UTF-8";
  518. return $mail->Send ();
  519. }
  520. function swfupload() {
  521. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  522. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  523. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  524. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  525. header ( "HTTP/1.1 500 Internal Server Error" );
  526. echo "POST exceeded maximum allowed size.";
  527. exit ( 0 );
  528. }
  529. // Settings
  530. $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)
  531. $upload_name = "Filedata";
  532. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  533. $extension_whitelist = array (
  534. "doc",
  535. "txt",
  536. "jpg",
  537. "gif",
  538. "png"
  539. ); // Allowed file extensions
  540. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  541. // Other variables
  542. $MAX_FILENAME_LENGTH = 260;
  543. $file_name = "";
  544. $file_extension = "";
  545. $uploadErrors = array (
  546. 0 => "文件上传成功",
  547. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  548. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  549. 3 => "上传的文件仅为部分文件",
  550. 4 => "没有文件上传",
  551. 6 => "缺少临时文件夹"
  552. );
  553. $nk = time ();
  554. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  555. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  556. echo "文件无法保存.";
  557. exit ( 0 );
  558. }
  559. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  560. echo json_encode ( array (
  561. 'filename' => $file_name,
  562. 'id' => $nk
  563. ) );
  564. exit ( 0 );
  565. }
  566. function _GetFileEXT($filename) {
  567. $pics = explode ( '.', $filename );
  568. $num = count ( $pics );
  569. return $pics [$num - 1];
  570. }
  571. /**
  572. * 获取get或者POST值
  573. * @param string $name 属性名称
  574. * @return fixed 值
  575. */
  576. function get_args($name) {
  577. if (isset ( $_GET [$name] )) {
  578. if (is_array ( $_GET [$name] ))
  579. return $_GET [$name];
  580. else
  581. return addslashes ( $_GET [$name] );
  582. } elseif (isset ( $_POST [$name] )) {
  583. if (is_array ( $_POST [$name] ))
  584. return $_POST [$name];
  585. else
  586. return addslashes ( $_POST [$name] );
  587. } else
  588. return false;
  589. }
  590. function num_to_rmb($num) {
  591. $c1 = "零壹贰叁肆伍陆柒捌玖";
  592. $c2 = "分角元拾佰仟万拾佰仟亿";
  593. // 精确到分后面就不要了,所以只留两个小数位
  594. $num = round ( $num, 2 );
  595. // 将数字转化为整数
  596. $num = $num * 100;
  597. if (strlen ( $num ) > 10) {
  598. return "金额太大,请检查";
  599. }
  600. $i = 0;
  601. $c = "";
  602. while ( 1 ) {
  603. if ($i == 0) {
  604. // 获取最后一位数字
  605. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  606. } else {
  607. $n = $num % 10;
  608. }
  609. // 每次将最后一位数字转化为中文
  610. $p1 = substr ( $c1, 3 * $n, 3 );
  611. $p2 = substr ( $c2, 3 * $i, 3 );
  612. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  613. $c = $p1 . $p2 . $c;
  614. } else {
  615. $c = $p1 . $c;
  616. }
  617. $i = $i + 1;
  618. // 去掉数字最后一位了
  619. $num = $num / 10;
  620. // echo $num.'</br>';
  621. $num = ( int ) $num;
  622. // $num =floor($num);
  623. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  624. // echo $num.'</br>';
  625. // 结束循环
  626. if ($num == 0) {
  627. break;
  628. }
  629. }
  630. // echo $c.'</br>';
  631. $j = 0;
  632. $slen = strlen ( $c );
  633. while ( $j < $slen ) {
  634. // utf8一个汉字相当3个字符
  635. $m = substr ( $c, $j, 6 );
  636. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  637. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  638. $left = substr ( $c, 0, $j );
  639. $right = substr ( $c, $j + 3 );
  640. $c = $left . $right;
  641. $j = $j - 3;
  642. $slen = $slen - 3;
  643. }
  644. $j = $j + 3;
  645. }
  646. // 这个是为了去掉类似23.0中最后一个“零”字
  647. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  648. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  649. }
  650. // 将处理的汉字加上“整”
  651. if (empty ( $c )) {
  652. return "零元整";
  653. } else {
  654. return $c . "整";
  655. }
  656. }
  657. /**
  658. * 获得分页数据
  659. * @param unknown_type $table
  660. * @param unknown_type $condition
  661. * @param unknown_type $on_page
  662. * @param unknown_type $page_size
  663. */
  664. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  665. $page_c = "";
  666. $page ['previous'] = $this->get_previous ( $on_page );
  667. $page ['on_page'] = $on_page;
  668. $total_count = $this->get_table_count ( $table, $condition );
  669. $total = intval ( $total_count / $page_size );
  670. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  671. $page ['total_data'] = $total_count;
  672. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  673. $i = 1;
  674. $page_max = 1;
  675. $page_width = 3;
  676. if ($on_page >= $page_width) {
  677. $page_max = intval ( $on_page / $page_width ) + 1;
  678. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  679. }
  680. for(; $i <= $page ['total_page']; $i ++) {
  681. if ($i == $on_page)
  682. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  683. else
  684. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  685. if ($i == ($page_width * $page_max))
  686. break;
  687. }
  688. $page ['page'] = $page_c;
  689. $page ['lower'] = (-- $on_page) * $page_size;
  690. return $page;
  691. }
  692. /**
  693. * 获取总页数
  694. * @param unknown_type $table
  695. * @param unknown_type $condition
  696. */
  697. public function get_table_count($table = "", $condition = "") {
  698. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  699. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  700. // echo $sql;die;
  701. $query = Doo::db ()->query ( $sql );
  702. $result = $query->fetch ();
  703. return $result ['count'];
  704. }
  705. /**
  706. * 获取上一页
  707. * @param unknown_type $on_page
  708. */
  709. function get_previous($on_page = 1) {
  710. return $on_page != 0 ? $on_page - 1 : $on_page;
  711. }
  712. }
  713. ?>