Recharge.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\library\Shande;
  4. use app\common\library\ShandeRapid;
  5. use app\common\library\Moyun;
  6. use think\Db;
  7. use think\Exception;
  8. use app\common\library\LianLianPay;
  9. require_once env('root_path').'application/common/library/llp/src/cfg.php';
  10. /**
  11. * @title 余额充值
  12. * @controller Recharge
  13. * @group base
  14. */
  15. class Recharge extends Base
  16. {
  17. public function initialize(){
  18. parent::initialize();
  19. parent::check_login();
  20. }
  21. /**
  22. * @title 余额充值
  23. * @desc 余额充值
  24. * @author Qc
  25. * @url /api/Recharge/voucher
  26. * @method POST
  27. * @header name:Authorization require:1 desc:Token
  28. * @param name:money type:int require:1 default:1 desc:充值金额
  29. * @param name:pay_type type:int require:1 default:sd_rapid desc:sd:杉德h5,sd_rapid:杉德快捷支付,moyun:墨云[支付宝],ll:连连支付
  30. * @param name:from type:int require:1 default1 desc:1:h5,2:app[Android],3:app[ios]
  31. * @return name:order_no type:string default:0 desc:支付单号
  32. * @return name:id type:int default:0 desc:支付订单id
  33. * @return name:extend type:int default:0 desc:用户id
  34. * @return name:pay type:array default:0 desc:支付信息
  35. * @return name:pay.body type:array default:0 desc:支付信息
  36. * @return name:pay.totalAmount type:string default:0 desc:支付金额【000000010000是100元】
  37. * @return name:pay.orderCode type:string default:0 desc:支付单号
  38. * @return name:pay.credential type:string default:0 desc:正书
  39. */
  40. public function voucher()
  41. {
  42. if(!checkAuth($this->uid)) $this->error('维护中.....');
  43. if (redisSetNx($this->request->action().$this->uid,3)) {
  44. $money = input('post.money',0);
  45. $pay_type = input('post.pay_type','sd_rapid');
  46. $from = input('post.from',1);
  47. $typecode = $from == 1 ? 4:5;
  48. if($money <=0 ) $this->error('充值金额有误!');
  49. $money = bcadd($money,0,2);
  50. if($money < 10 && $this->uid != 73)$this->error('最低充值10元!');
  51. if($pay_type != 'll')$this->error('维护中,请选择其他支付方式');
  52. $user = Db::name('store_member')->where('id',$this->uid)->find();
  53. if(!$user['true_name'] || !$user['id_card']) $this->error('请实名认证,在进行订单支付');
  54. Db::startTrans();
  55. try{
  56. $voucher_order = [
  57. 'mid' => $this->uid ,
  58. 'total_price' => $money,
  59. 'order_no' =>get_order_sn(),
  60. 'pay_no' =>get_order_sn(),
  61. 'create_at' => date("Y-m-d H:i:s"),
  62. 'pay_type' => $pay_type,
  63. 'ext' => json_encode(['name'=>$user['true_name'],'phone'=>$user['phone'],'id_card'=>$user['id_card']])
  64. ];
  65. $order_id = Db::table('store_recharge_order')->insertGetId($voucher_order);
  66. $notify_url = 'https://'.$_SERVER['HTTP_HOST'] . '/api/Pay/walletNotify';
  67. switch ($pay_type)
  68. {
  69. case 'sd':
  70. $client = new Shande();
  71. $total_fee = $money*100;
  72. $lenth = strlen($total_fee);
  73. $total_fee = get0number($lenth).$total_fee;
  74. $result = $client->orderPay($voucher_order['order_no'],$total_fee,'订单充值',$notify_url,'https://'.$_SERVER['HTTP_HOST'].'/h5/pages/mine/mine',$user['bank_num']);
  75. $retrun_data['order_no'] = $voucher_order['order_no'];
  76. $retrun_data['extend'] = $this->uid;
  77. $retrun_data['pay'] = json_decode($result['data'],true);
  78. if( $retrun_data['pay']['head']['respCode'] != '00000')$this->error($retrun_data['pay']['head']['respMsg'].'请重新下单');
  79. break;
  80. case 'sd_rapid':
  81. $rapid = new ShandeRapid();
  82. $return_url ='https://'.$_SERVER['HTTP_HOST']."/h5/pages/mine/mine?id={$order_id}&orderNo={$voucher_order['order_no']}";//回调地址
  83. $pay_extra = json_encode(['userId'=>"$this->uid",'userName'=>$user['true_name'],'idCard'=>$user['id_card']]);
  84. $pay_url = $rapid->payOrder($voucher_order['order_no'],$money,$notify_url,$return_url,$pay_extra,'余额充值');
  85. parse_str(parse_url($pay_url)['query'],$pay_query);
  86. $retrun_data['parse_url'] = parse_url($pay_url)['query'];
  87. $retrun_data['order_no'] = $voucher_order['order_no'];
  88. $retrun_data['extend'] = $this->uid;
  89. $retrun_data['pay_url'] = $pay_url;
  90. $retrun_data['pay_query'] = $pay_query;
  91. break;
  92. case 'moyun':
  93. $obj = new Moyun();
  94. $notifyUrl = 'https://'.$_SERVER['HTTP_HOST'].'/api/Pay/moYunWalletNotify';//回调地址
  95. $return_url ='https://'.$_SERVER['HTTP_HOST']."/h5/pages/mine/mine?id={$order_id}&orderNo={$voucher_order['order_no']}";//回调地址
  96. $res = $obj->alipay('余额充值',$voucher_order['order_no'],$money,'',$notifyUrl,$return_url,$typecode);
  97. // if($this->uid == 73) var_dump($retrun_data);
  98. if(!isset($res['data']) || !$res['data']) throw new Exception($res['msg']);
  99. $retrun_data = $res['data'];
  100. break;
  101. case 'll':
  102. $notify_url = 'https://'.$_SERVER['HTTP_HOST'] . '/api/Pay/lianLianNotify';
  103. $return_url ='https://'.$_SERVER['HTTP_HOST']."/h5/pages/mine/mine?id={$order_id}&orderNo={$voucher_order['order_no']}";//回调地址
  104. $risk_item= risk_item($user,'订单支付',$from == 1 ? 16 : 10);
  105. $res= LianLianPay::cashierPay($voucher_order['order_no'],$money,$this->uid,$notify_url,$return_url,'余额充值',[[
  106. 'payee_id'=>OID_PARTNER,
  107. 'payee_type' => 'MERCHANT',
  108. 'payee_amount' => $money,
  109. ]],$risk_item);
  110. $retrun_data = $res['pay_result'];
  111. break;
  112. }
  113. Db::commit();
  114. }catch (\Exception $e){
  115. Db::rollback();
  116. DelRedisSetNx($this->request->action().$this->uid);
  117. $this->error($e->getMessage());
  118. }
  119. DelRedisSetNx($this->request->action().$this->uid);
  120. $this->success('ok',$retrun_data);
  121. }else{
  122. $this->error('服务器繁忙');
  123. }
  124. }
  125. /**
  126. * @title 云钱包余额充值
  127. * @desc 云钱包余额充值
  128. * @author Qc
  129. * @url /api/Recharge/cloudWalletVoucher
  130. * @method POST
  131. * @header name:Authorization require:1 desc:Token
  132. * @param name:money type:int require:1 default:1 desc:充值金额
  133. * @param name:from type:int require:1 default1 desc:1:h5,2:app[Android],3:app[ios]
  134. * @return name:order_no type:string default:0 desc:支付单号
  135. * @return name:id type:int default:0 desc:支付订单id
  136. * @return name:extend type:int default:0 desc:用户id
  137. * @return name:pay type:array default:0 desc:支付信息
  138. * @return name:pay.body type:array default:0 desc:支付信息
  139. * @return name:pay.totalAmount type:string default:0 desc:支付金额【000000010000是100元】
  140. * @return name:pay.orderCode type:string default:0 desc:支付单号
  141. * @return name:pay.credential type:string default:0 desc:正书
  142. */
  143. public function cloudWalletVoucher()
  144. {
  145. if(!checkAuth($this->uid)) $this->error('维护中.....');
  146. if (redisSetNx($this->request->action().$this->uid,3)) {
  147. $money = input('post.money',0);
  148. $from = input('post.from',1);
  149. if($money <=0 ) $this->error('充值金额有误!');
  150. $money = bcadd($money,0,2);
  151. $user = Db::name('store_member')->where('id',$this->uid)->find();
  152. if(!$user['true_name'] || !$user['id_card']) $this->error('请实名认证,在进行订单支付');
  153. Db::startTrans();
  154. try{
  155. $voucher_order = [
  156. 'mid' => $this->uid ,
  157. 'total_price' => $money,
  158. 'order_no' =>get_order_sn(),
  159. 'pay_no' =>get_order_sn(),
  160. 'create_at' => date("Y-m-d H:i:s"),
  161. 'pay_type' => 'll',
  162. 'ext' => json_encode(['name'=>$user['true_name'],'phone'=>$user['phone'],'id_card'=>$user['id_card']])
  163. ];
  164. $order_id = Db::table('cloud_wallet_order')->insertGetId($voucher_order);
  165. $notify_url = 'https://'.$_SERVER['HTTP_HOST'] . '/api/Notify/cloudWalletNotify';
  166. $return_url ='https://'.$_SERVER['HTTP_HOST']."/h5/pages/mine/mine?id={$order_id}&orderNo={$voucher_order['order_no']}";//回调地址
  167. $risk_item= risk_item($user,'余额充值',$from == 1 ? 16 : 10);
  168. $res= LianLianPay::cloudWalletRecharge($voucher_order['order_no'],$money,$this->uid,$notify_url,$return_url,'余额充值',$risk_item);
  169. $retrun_data = $res['pay_result'];
  170. Db::commit();
  171. }catch (\Exception $e){
  172. Db::rollback();
  173. DelRedisSetNx($this->request->action().$this->uid);
  174. $this->error($e->getMessage());
  175. }
  176. DelRedisSetNx($this->request->action().$this->uid);
  177. $this->success('ok',$retrun_data);
  178. }else{
  179. $this->error('服务器繁忙');
  180. }
  181. }
  182. }