global.func.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * 生成流水号
  4. */
  5. function create_sn(){
  6. mt_srand((double )microtime() * 1000000 );
  7. return date("YmdHis" ).str_pad( mt_rand( 1, 99999 ), 5, "0", STR_PAD_LEFT );
  8. }
  9. /**
  10. * 返回响应地址
  11. */
  12. function return_url($code, $is_api = 0){
  13. if($is_api){
  14. return APP_PATH.'index.php?m=pay&c=respond&a=respond_post&code='.$code;
  15. }
  16. else {
  17. return APP_PATH.'index.php?m=pay&c=respond&a=respond_get&code='.$code;
  18. }
  19. }
  20. function unserialize_config($cfg){
  21. if (is_string($cfg) ) {
  22. $arr = string2array($cfg);
  23. $config = array();
  24. foreach ($arr AS $key => $val) {
  25. $config[$key] = $val['value'];
  26. }
  27. return $config;
  28. } else {
  29. return false;
  30. }
  31. }
  32. /**
  33. * 返回订单状态
  34. */
  35. function return_status($status) {
  36. $trade_status = array('0'=>'succ', '1'=>'failed', '2'=>'timeout', '3'=>'progress', '4'=>'unpay', '5'=>'cancel','6'=>'error');
  37. return $trade_status[$status];
  38. }
  39. /**
  40. * 返回订单手续费
  41. * @param $amount 订单价格
  42. * @param $fee 手续费比率
  43. * @param $method 手续费方式
  44. */
  45. function pay_fee($amount, $fee=0, $method=0) {
  46. $pay_fee = 0;
  47. if($method == 0) {
  48. $val = floatval($fee) / 100;
  49. $pay_fee = $val > 0 ? $amount * $val : 0;
  50. } elseif($method == 1) {
  51. $pay_fee = $fee;
  52. }
  53. return round($pay_fee, 2);
  54. }
  55. /**
  56. * 生成支付按钮
  57. * @param $data 按钮数据
  58. * @param $attr 按钮属性 如样式等
  59. * @param $ishow 是否显示描述
  60. */
  61. function mk_pay_btn($data,$attr='class="payment-show"',$ishow='1') {
  62. $pay_type = '';
  63. if(is_array($data)){
  64. foreach ($data as $v) {
  65. $pay_type .= '<label '.$attr.'>';
  66. $pay_type .='<input name="pay_type" type="radio" value="'.$v['pay_id'].'"> <em>'.$v['name'].'</em>';
  67. $pay_type .=$ishow ? '<span class="payment-desc">'.$v['pay_desc'].'</span>' :'';
  68. $pay_type .= '</label>';
  69. }
  70. }
  71. return $pay_type;
  72. }
  73. ?>