ReceiptAjaxController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  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. $days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
  277. $startYear=$year."-".$month."-01:00.00.00";
  278. $endYear=$year."-".$month."-".$days.":23.59.59";
  279. // $con = ' and year(inputDate) = "'.$year.'" and month(inputDate)="'.$month.'"';
  280. $con =' and inputDate>= "'.$startYear.'" and inputDate<="'.$endYear.'" ';
  281. //收入
  282. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  283. //支出
  284. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  285. //print_r($incomeList);
  286. $firstday = date('Y-m-01', strtotime(date("Y-m-d")));
  287. // $lastday = date('d', strtotime("$firstday +1 month -1 day"));
  288. $lastday = $days;
  289. //print_r($incomeList);
  290. //导入流水func
  291. Doo::loadClass ( 'receipt.finances.func' );
  292. //1-0获得这月之前的所有金额合计
  293. include './protected/config/wasteBook.conf.php';
  294. $balance=$wbBalance;
  295. $balanceSum=$wasteBook->getStatisticsByMonthAll($year,$month);
  296. if(!empty($balanceSum[0]['accountPrice'])){
  297. $balance+=$balanceSum[0]['accountPrice'];
  298. }
  299. $data=array();
  300. //1-1 日排序
  301. for($day=$lastday;$day>0;$day--){
  302. $data[$year.'-'.str_pad($month,2,'0',STR_PAD_LEFT).'-'.str_pad($day,2,'0',STR_PAD_LEFT)]=array();
  303. }
  304. //1-2 设置流水收入
  305. foreach ($incomeList as $key=>$value){
  306. $inputDate=date('Y-m-d', strtotime($value['inputDate']));
  307. $item['inputDate']=$inputDate;
  308. //TODO-收款和日常收入-付款单位
  309. $item['receivablesMessage']='';
  310. if($value['accountType']==5||$value['accountType']==6){
  311. $item['receivablesMessage']=$value['data']['remarks'];
  312. }elseif($value['accountType']==7){
  313. $item['receivablesMessage']=$value['data']['receivablesMessage'];
  314. }
  315. //类型
  316. $item['revenueType']='';
  317. if($value['expensesType']==1){
  318. $item['revenueType']=_getRevenueTypeCN($value);
  319. }
  320. $item['category']=$value['category'];
  321. //结算方式--只有发票和收款才有
  322. $item['settlementType']='';
  323. if($value['accountType']==8||$value['accountType']==7){
  324. if(isset($value['data']['settlementType'])){
  325. $item['settlementType']='软件销售';
  326. if($value['data']['settlementType']==1){
  327. $item['settlementType']='培训班';
  328. }
  329. }
  330. }
  331. $item['revenueBankMsg']=$value['accountBankMsg'];
  332. $item['revenuePriceShow']=$value['accountPriceShow'];
  333. $item['revenueTotalDay']='';
  334. //echo $inputDate.'</br>';
  335. array_push($data[$inputDate], $item);
  336. }
  337. //print_r($incomeList);
  338. //组合支出
  339. //1-3设置支出
  340. $bakDate=0;
  341. foreach ($expenditureList as $key=>$value){
  342. $inputDate=date('Y-m-d', strtotime($value['inputDate']));
  343. if($bakDate!=$inputDate){
  344. $bakDate=$inputDate;
  345. $index=0;
  346. }
  347. if(isset($data[$inputDate][$index])){
  348. //费用类别
  349. $item['outlayType']=_getOutlayTypeCN($value);
  350. //支出内容
  351. $item['outlayMsg']=' /'.$value['category'];
  352. if($value['accountType']==5||$value['accountType']==9||$value['accountType']==10){
  353. $item['outlayMsg']=$value['data']['remarks'];
  354. }
  355. $item['outlayBankMsg']=$value['accountBankMsg'];
  356. $item['outlayPriceShow']=$value['accountPriceShow'];
  357. $data[$inputDate][$index]+=$item;
  358. }else{
  359. $item['inputDate']=$inputDate;
  360. $item['receivablesMessage']='';
  361. $item['revenueType']='';
  362. $item['category']='';
  363. $item['settlementType']='';
  364. $item['revenueBankMsg']='';
  365. $item['revenuePriceShow']='';
  366. //支出项
  367. //费用类别
  368. $item['outlayType']=_getOutlayTypeCN($value);
  369. //支出内容
  370. $item['outlayMsg']='/'.$value['category'];
  371. $item['outlayBankMsg']=$value['accountBankMsg'];
  372. $item['outlayPriceShow']=$value['accountPriceShow'];
  373. $item['outlayTotalDay']='';
  374. array_push($data[$inputDate], $item);
  375. }
  376. $index++;
  377. }
  378. //TODO 1-4 计算每日合计
  379. $revenueTotalMonthPrice=$outlayTotalMonthPrice=0;
  380. foreach ($data as $key=>$value){
  381. if(!empty($value)){
  382. $revenueTotalDayPrice=$outlayTotalDayPrice=0;
  383. foreach ($value as $v){
  384. if(isset($v['revenuePriceShow'])){
  385. $revenueTotalDayPrice+=$v['revenuePriceShow'];
  386. $revenueTotalMonthPrice+=$v['revenuePriceShow'];
  387. }
  388. if(isset($v['outlayPriceShow'])){
  389. $outlayTotalDayPrice+=$v['outlayPriceShow'];
  390. $outlayTotalMonthPrice+=$v['outlayPriceShow'];
  391. }
  392. }
  393. $item=_structureReportItem('','','','','','','今日总收入',number_format($revenueTotalDayPrice,2)
  394. ,'','','','今日总支出',number_format($outlayTotalDayPrice,2));
  395. $item['balance']=bcadd($balance,$revenueTotalDayPrice-$outlayTotalDayPrice,2);
  396. array_push($data[$key], $item);
  397. }
  398. }
  399. $pieDetailData=array();
  400. foreach ($data as $key=>$value){
  401. //$pieDetailData[$key]=array();
  402. $revenueTotalDay=$outlayTotalDay=0;
  403. if(!empty($value)){
  404. $item=end($value);
  405. if (isset($item['revenueTotalDay'])){
  406. $revenueTotalDay=str_replace(',','',$item['revenueTotalDay']);
  407. }
  408. if(isset($item['revenueTotalDay'])){
  409. $outlayTotalDay=str_replace(',','',$item['outlayTotalDay']);
  410. }
  411. }
  412. if($revenueTotalDay!=0&&$outlayTotalDay!=0){
  413. $pieDetailData[$key]=array($revenueTotalDay,$outlayTotalDay);
  414. }
  415. //array_push($pieDetailData[$key], array($revenueTotalDay,$outlayTotalDay));
  416. }
  417. //print_r($pieDetailData);
  418. //格式化数据
  419. $item=_structureReportItem('月初金额','','','','','','',0
  420. ,'','','','',0);
  421. $item['key']='balance';
  422. $item['balance']=$balance;
  423. $jsonList[0]= $item;
  424. $item=_structureReportItem('','','','','','','总收入',number_format($revenueTotalMonthPrice,2)
  425. ,'','','','总支出',number_format($outlayTotalMonthPrice,2));
  426. $item['balance']=bcadd($balance,$revenueTotalMonthPrice-$outlayTotalMonthPrice,2);
  427. $item['key']='summary';
  428. $jsonList[1]= $item;
  429. //$jsonList=array();
  430. $dayList=array();
  431. foreach ($data as $key=>$value){
  432. foreach ($value as $k=>$v){
  433. $v['key']=$k;
  434. array_push($jsonList, $v);
  435. array_push($dayList, $key);
  436. }
  437. }
  438. //echo $firstday;
  439. //print_r($incomeList);
  440. // $item=_structureReportItem('','','','','','','总收入',number_format($revenueTotalMonthPrice,2)
  441. // ,'','','','总支出',number_format($outlayTotalMonthPrice,2));
  442. // $item['balance']=$balance+$revenueTotalMonthPrice-$outlayTotalMonthPrice;
  443. // $item['key']='summary';
  444. // array_push($jsonList, $item);
  445. //日期筛选数据
  446. $dayList=array_unique($dayList);
  447. $list=array();
  448. foreach ($dayList as $value){
  449. array_push($list, array('text'=>$value,'value'=>$value));
  450. }
  451. //print_r(array_values($dayList));
  452. echo json_encode ( array (
  453. 'reportData' => $jsonList,
  454. 'reportDay'=>$list,
  455. 'reportDateStart'=>$year.'-'.str_pad(($month),2,"0",STR_PAD_LEFT),
  456. 'reportDateEnd'=>$year.'-'.str_pad(($month+1),2,"0",STR_PAD_LEFT),
  457. 'pieDetailData'=>$pieDetailData,
  458. ) );
  459. //echo json_encode($jsonList);
  460. }
  461. function setWXMsg($rid, $type) {
  462. Doo::loadModel ( "receipt" );
  463. $receipt = new receipt ();
  464. $receiptDetail = $receipt->getOne ( array (
  465. 'where' => 'rid=' . $rid,
  466. 'asArray' => true
  467. ) );
  468. if (! empty ( $receiptDetail )) {
  469. Doo::loadModel ( 'staff' );
  470. $staff = new staff ();
  471. $staffmsg = $staff->getOne ( array (
  472. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  473. 'asArray' => TRUE
  474. ) );
  475. if (! empty ( $staffmsg ['wxid'] )) {
  476. require_once (SITE_PATH . '/protected/class/client.php');
  477. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  478. $user = $staffmsg ['wxid'];
  479. $receiptName = '';
  480. $msg = '';
  481. switch ($receiptDetail ['Rtype']) {
  482. case 0 :
  483. $receiptName = '报销';
  484. break;
  485. case 1 :
  486. $receiptName = '借款';
  487. break;
  488. case 2 :
  489. $receiptName = '对公汇款';
  490. break;
  491. }
  492. switch ($type) {
  493. case 1 :
  494. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  495. break;
  496. case 2 :
  497. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  498. break;
  499. case 3 :
  500. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  501. break;
  502. }
  503. // $result = $client->SendMsg ( $user, $msg, 'text' );
  504. }
  505. }
  506. }
  507. // Email发送函数
  508. function SMail($toemail, $subject, $contents) {
  509. Doo::loadClass ( 'class.phpmailer' );
  510. $mail = new PHPMailer ();
  511. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  512. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  513. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  514. $mail->Password = "cDO1GjtY1seH"; // 密码
  515. $mail->CharSet = "UTF8";
  516. $mail->SMTPAuth = true;
  517. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  518. $mail->Mailer = "smtp";
  519. $mail->Port = 25;
  520. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  521. $mail->MsgHTML ( $contents );
  522. $mail->AddAddress ( $toemail );
  523. $mail->CharSet = "UTF-8";
  524. return $mail->Send ();
  525. }
  526. function swfupload() {
  527. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  528. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  529. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  530. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  531. header ( "HTTP/1.1 500 Internal Server Error" );
  532. echo "POST exceeded maximum allowed size.";
  533. exit ( 0 );
  534. }
  535. // Settings
  536. $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)
  537. $upload_name = "Filedata";
  538. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  539. $extension_whitelist = array (
  540. "doc",
  541. "txt",
  542. "jpg",
  543. "gif",
  544. "png"
  545. ); // Allowed file extensions
  546. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  547. // Other variables
  548. $MAX_FILENAME_LENGTH = 260;
  549. $file_name = "";
  550. $file_extension = "";
  551. $uploadErrors = array (
  552. 0 => "文件上传成功",
  553. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  554. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  555. 3 => "上传的文件仅为部分文件",
  556. 4 => "没有文件上传",
  557. 6 => "缺少临时文件夹"
  558. );
  559. $nk = time ();
  560. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  561. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  562. echo "文件无法保存.";
  563. exit ( 0 );
  564. }
  565. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  566. echo json_encode ( array (
  567. 'filename' => $file_name,
  568. 'id' => $nk
  569. ) );
  570. exit ( 0 );
  571. }
  572. function _GetFileEXT($filename) {
  573. $pics = explode ( '.', $filename );
  574. $num = count ( $pics );
  575. return $pics [$num - 1];
  576. }
  577. /**
  578. * 获取get或者POST值
  579. * @param string $name 属性名称
  580. * @return fixed 值
  581. */
  582. function get_args($name) {
  583. if (isset ( $_GET [$name] )) {
  584. if (is_array ( $_GET [$name] ))
  585. return $_GET [$name];
  586. else
  587. return addslashes ( $_GET [$name] );
  588. } elseif (isset ( $_POST [$name] )) {
  589. if (is_array ( $_POST [$name] ))
  590. return $_POST [$name];
  591. else
  592. return addslashes ( $_POST [$name] );
  593. } else
  594. return false;
  595. }
  596. function num_to_rmb($num) {
  597. $c1 = "零壹贰叁肆伍陆柒捌玖";
  598. $c2 = "分角元拾佰仟万拾佰仟亿";
  599. // 精确到分后面就不要了,所以只留两个小数位
  600. $num = round ( $num, 2 );
  601. // 将数字转化为整数
  602. $num = $num * 100;
  603. if (strlen ( $num ) > 10) {
  604. return "金额太大,请检查";
  605. }
  606. $i = 0;
  607. $c = "";
  608. while ( 1 ) {
  609. if ($i == 0) {
  610. // 获取最后一位数字
  611. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  612. } else {
  613. $n = $num % 10;
  614. }
  615. // 每次将最后一位数字转化为中文
  616. $p1 = substr ( $c1, 3 * $n, 3 );
  617. $p2 = substr ( $c2, 3 * $i, 3 );
  618. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  619. $c = $p1 . $p2 . $c;
  620. } else {
  621. $c = $p1 . $c;
  622. }
  623. $i = $i + 1;
  624. // 去掉数字最后一位了
  625. $num = $num / 10;
  626. // echo $num.'</br>';
  627. $num = ( int ) $num;
  628. // $num =floor($num);
  629. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  630. // echo $num.'</br>';
  631. // 结束循环
  632. if ($num == 0) {
  633. break;
  634. }
  635. }
  636. // echo $c.'</br>';
  637. $j = 0;
  638. $slen = strlen ( $c );
  639. while ( $j < $slen ) {
  640. // utf8一个汉字相当3个字符
  641. $m = substr ( $c, $j, 6 );
  642. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  643. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  644. $left = substr ( $c, 0, $j );
  645. $right = substr ( $c, $j + 3 );
  646. $c = $left . $right;
  647. $j = $j - 3;
  648. $slen = $slen - 3;
  649. }
  650. $j = $j + 3;
  651. }
  652. // 这个是为了去掉类似23.0中最后一个“零”字
  653. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  654. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  655. }
  656. // 将处理的汉字加上“整”
  657. if (empty ( $c )) {
  658. return "零元整";
  659. } else {
  660. return $c . "整";
  661. }
  662. }
  663. /**
  664. * 获得分页数据
  665. * @param unknown_type $table
  666. * @param unknown_type $condition
  667. * @param unknown_type $on_page
  668. * @param unknown_type $page_size
  669. */
  670. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  671. $page_c = "";
  672. $page ['previous'] = $this->get_previous ( $on_page );
  673. $page ['on_page'] = $on_page;
  674. $total_count = $this->get_table_count ( $table, $condition );
  675. $total = intval ( $total_count / $page_size );
  676. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  677. $page ['total_data'] = $total_count;
  678. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  679. $i = 1;
  680. $page_max = 1;
  681. $page_width = 3;
  682. if ($on_page >= $page_width) {
  683. $page_max = intval ( $on_page / $page_width ) + 1;
  684. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  685. }
  686. for(; $i <= $page ['total_page']; $i ++) {
  687. if ($i == $on_page)
  688. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  689. else
  690. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  691. if ($i == ($page_width * $page_max))
  692. break;
  693. }
  694. $page ['page'] = $page_c;
  695. $page ['lower'] = (-- $on_page) * $page_size;
  696. return $page;
  697. }
  698. /**
  699. * 获取总页数
  700. * @param unknown_type $table
  701. * @param unknown_type $condition
  702. */
  703. public function get_table_count($table = "", $condition = "") {
  704. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  705. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  706. // echo $sql;die;
  707. $query = Doo::db ()->query ( $sql );
  708. $result = $query->fetch ();
  709. return $result ['count'];
  710. }
  711. /**
  712. * 获取上一页
  713. * @param unknown_type $on_page
  714. */
  715. function get_previous($on_page = 1) {
  716. return $on_page != 0 ? $on_page - 1 : $on_page;
  717. }
  718. }
  719. ?>