comm_cld.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * 获取get或者POST值
  4. *
  5. * @param string $name 属性名称
  6. * @return fixed 值
  7. */
  8. function get_args($name) {
  9. if (isset ( $_GET [$name] )) {
  10. return $_GET [$name];
  11. } elseif (isset ( $_POST [$name] )) {
  12. return $_POST [$name];
  13. } else
  14. return '';
  15. }
  16. function GetDecryptId($id){
  17. Doo::loadClass ( 'XDeode' );
  18. $XDeode = new XDeode ( 9 );
  19. $id=$XDeode->decode($id);
  20. if (!is_numeric($id)){
  21. die ( 'illegal request-参数解析错误' );
  22. }
  23. return $id;
  24. }
  25. function makeReceiptDataVersion1($receiptList){
  26. //办事处费用
  27. $receiptList[0]['officeJson']=json_decode($receiptList[0]['officeJson'],true);
  28. if (!empty($receiptList[0]['officeJson'])){
  29. $receiptList[0]['officeExplain']="<pre>".$receiptList[0]['officeJson']['officeExplain'][0]['officeExplain']."</pre>";
  30. $total=0;
  31. foreach ($receiptList[0]['officeJson']['daily'] as $value){
  32. $total=bcadd($total,$value['price'],2);
  33. }
  34. $receiptList[0]['dailyTotal']=$total;
  35. $total=0;
  36. foreach ($receiptList[0]['officeJson']['other'] as $value){
  37. $total=bcadd($total,$value['price'],2);
  38. }
  39. $receiptList[0]['otherTotal']=$total;
  40. $receiptList[0]['officeTotal']=bcadd($receiptList[0]['otherTotal'],$receiptList[0]['dailyTotal'],2);
  41. }
  42. //差旅费用
  43. $traveJson=json_decode($receiptList[0]['traveJson'],true);
  44. $receiptList[0]['traveJson']=$traveJson;
  45. if (!empty($receiptList[0]['traveJson'])){
  46. $receiptList[0]['traveExplain']="<pre>".$receiptList[0]['traveJson']['traveExplain'][0]['traveExplain']."</pre>";
  47. $total=0;
  48. foreach ($traveJson['traveList'] as $key=>$value){
  49. $receiptList[0]['traveJson']['traveList'][$key]['index']=$key+1;
  50. $detailCity='';
  51. $tripTotal=0;
  52. $tripItem=array();
  53. //1.行程list
  54. foreach ($value['tripList'] as $k=>$v){
  55. //2.组合各个城市
  56. if(count($value['tripList'])==($k+1)){
  57. $detailCity.=$v['city'];
  58. }else{
  59. $detailCity.=$v['city'].' - ';
  60. }
  61. //3.组合列详情
  62. foreach ($v['tripItem'] as $tk=>$tv){
  63. if (!isset($tripItem[$tv['name']])){
  64. $tripItem[$tv['name']]=0;
  65. }
  66. $tripItem[$tv['name']]=bcadd($tripItem[$tv['name']],$tv['price'],2);
  67. //3.行程金额小计
  68. $tripTotal=bcadd($tripTotal,$tv['price'],2);
  69. }
  70. $count=count($value['tripList'])-1;
  71. if($count>$k){
  72. $index=$k+1;
  73. $receiptList[0]['traveJson']['traveList'][$key]['tripList'][$k]['goCome']=$v['city'].'-'.$value['tripList'][$index]['city'];
  74. }
  75. $total=bcadd($total,$v['subtotal'],2);
  76. }
  77. $receiptList[0]['traveJson']['traveList'][$key]['detailCity']=$detailCity;
  78. $receiptList[0]['traveJson']['traveList'][$key]['detailTrip']=$tripItem;
  79. $receiptList[0]['traveJson']['traveList'][$key]['tripTotal']=$tripTotal;
  80. }
  81. $receiptList[0]['traveTotal']=$total;
  82. //print_r($receiptList[0]['traveJson']);
  83. }
  84. //内训费用
  85. $receiptList[0]['trainJson']=json_decode($receiptList[0]['trainJson'],true);
  86. if (!empty($receiptList[0]['trainJson'])){
  87. $receiptList[0]['trainExplain']="<pre>".$receiptList[0]['trainJson']['trainExplain'][0]['trainExplain']."</pre>";
  88. $total=0;
  89. foreach ($receiptList[0]['trainJson']['train'] as $value){
  90. $total=bcadd($total,$value['price'],2);
  91. }
  92. $receiptList[0]['trainTotal']=$total;
  93. }
  94. return $receiptList;
  95. }
  96. function num_to_rmb($num) {
  97. $c1 = "零壹贰叁肆伍陆柒捌玖";
  98. $c2 = "分角元拾佰仟万拾佰仟亿";
  99. // 精确到分后面就不要了,所以只留两个小数位
  100. $num = round ( $num, 2 );
  101. // 将数字转化为整数
  102. $num = $num * 100;
  103. if (strlen ( $num ) > 10) {
  104. return "金额太大,请检查";
  105. }
  106. $i = 0;
  107. $c = "";
  108. while ( 1 ) {
  109. if ($i == 0) {
  110. // 获取最后一位数字
  111. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  112. } else {
  113. $n = $num % 10;
  114. }
  115. // 每次将最后一位数字转化为中文
  116. $p1 = substr ( $c1, 3 * $n, 3 );
  117. $p2 = substr ( $c2, 3 * $i, 3 );
  118. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  119. $c = $p1 . $p2 . $c;
  120. } else {
  121. $c = $p1 . $c;
  122. }
  123. $i = $i + 1;
  124. // 去掉数字最后一位了
  125. $num = $num / 10;
  126. // echo $num.'</br>';
  127. $num = ( int ) $num;
  128. // $num =floor($num);
  129. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  130. // echo $num.'</br>';
  131. // 结束循环
  132. if ($num == 0) {
  133. break;
  134. }
  135. }
  136. // echo $c.'</br>';
  137. $j = 0;
  138. $slen = strlen ( $c );
  139. while ( $j < $slen ) {
  140. // utf8一个汉字相当3个字符
  141. $m = substr ( $c, $j, 6 );
  142. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  143. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  144. $left = substr ( $c, 0, $j );
  145. $right = substr ( $c, $j + 3 );
  146. $c = $left . $right;
  147. $j = $j - 3;
  148. $slen = $slen - 3;
  149. }
  150. $j = $j + 3;
  151. }
  152. // 这个是为了去掉类似23.0中最后一个“零”字
  153. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  154. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  155. }
  156. // 将处理的汉字加上“整”
  157. if (empty ( $c )) {
  158. return "零元整";
  159. } else {
  160. return $c . "整";
  161. }
  162. }
  163. ?>