123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php
- namespace app\api\controller;
- use app\common\library\Shande;
- use app\common\library\ShandeRapid;
- use app\common\library\Moyun;
- use think\Db;
- use think\Exception;
- use app\common\library\LianLianPay;
- require_once env('root_path').'application/common/library/llp/src/cfg.php';
- /**
- * @title 余额充值
- * @controller Recharge
- * @group base
- */
- class Recharge extends Base
- {
- public function initialize(){
- parent::initialize();
- parent::check_login();
- }
- /**
- * @title 余额充值
- * @desc 余额充值
- * @author Qc
- * @url /api/Recharge/voucher
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:money type:int require:1 default:1 desc:充值金额
- * @param name:pay_type type:int require:1 default:sd_rapid desc:sd:杉德h5,sd_rapid:杉德快捷支付,moyun:墨云[支付宝],ll:连连支付
- * @param name:from type:int require:1 default1 desc:1:h5,2:app[Android],3:app[ios]
- * @return name:order_no type:string default:0 desc:支付单号
- * @return name:id type:int default:0 desc:支付订单id
- * @return name:extend type:int default:0 desc:用户id
- * @return name:pay type:array default:0 desc:支付信息
- * @return name:pay.body type:array default:0 desc:支付信息
- * @return name:pay.totalAmount type:string default:0 desc:支付金额【000000010000是100元】
- * @return name:pay.orderCode type:string default:0 desc:支付单号
- * @return name:pay.credential type:string default:0 desc:正书
- * @return name:txn_seqno type:string default:0 desc:支付单号【连连支付】
- * @return name:total_amount type:string default:0 desc:金额【连连支付】
- * @return name:gateway_url type:string default:0 desc:支付地址【连连支付】
- */
- public function voucher()
- {
- if(!checkAuth($this->uid)) $this->error('维护中.....');
- if (redisSetNx($this->request->action().$this->uid,3)) {
- $money = input('post.money',0);
- $pay_type = input('post.pay_type','sd_rapid');
- $from = input('post.from',1);
- $typecode = $from == 1 ? 4:5;
- if($money <=0 ) $this->error('充值金额有误!');
- $money = bcadd($money,0,2);
- if($money < 10 && $this->uid != 73)$this->error('最低充值10元!');
- if($pay_type != 'll')$this->error('维护中,请选择其他支付方式');
- $user = Db::name('store_member')->where('id',$this->uid)->find();
- if(!$user['true_name'] || !$user['id_card']) $this->error('请实名认证,在进行订单支付');
- Db::startTrans();
- try{
- $voucher_order = [
- 'mid' => $this->uid ,
- 'total_price' => $money,
- 'order_no' =>get_order_sn(),
- 'pay_no' =>get_order_sn(),
- 'create_at' => date("Y-m-d H:i:s"),
- 'pay_type' => $pay_type,
- 'ext' => json_encode(['name'=>$user['true_name'],'phone'=>$user['phone'],'id_card'=>$user['id_card']])
- ];
- $order_id = Db::table('store_recharge_order')->insertGetId($voucher_order);
- $notify_url = 'https://'.$_SERVER['HTTP_HOST'] . '/api/Pay/walletNotify';
- switch ($pay_type)
- {
- case 'sd':
- $client = new Shande();
- $total_fee = $money*100;
- $lenth = strlen($total_fee);
- $total_fee = get0number($lenth).$total_fee;
- $result = $client->orderPay($voucher_order['order_no'],$total_fee,'订单充值',$notify_url,'https://'.$_SERVER['HTTP_HOST'].'/h5/pages/mine/mine',$user['bank_num']);
- $retrun_data['order_no'] = $voucher_order['order_no'];
- $retrun_data['extend'] = $this->uid;
- $retrun_data['pay'] = json_decode($result['data'],true);
- if( $retrun_data['pay']['head']['respCode'] != '00000')$this->error($retrun_data['pay']['head']['respMsg'].'请重新下单');
- break;
- case 'sd_rapid':
- $rapid = new ShandeRapid();
- $return_url ='https://'.$_SERVER['HTTP_HOST']."/h5/pages/mine/mine?id={$order_id}&orderNo={$voucher_order['order_no']}";//回调地址
- $pay_extra = json_encode(['userId'=>"$this->uid",'userName'=>$user['true_name'],'idCard'=>$user['id_card']]);
- $pay_url = $rapid->payOrder($voucher_order['order_no'],$money,$notify_url,$return_url,$pay_extra,'余额充值');
- parse_str(parse_url($pay_url)['query'],$pay_query);
- $retrun_data['parse_url'] = parse_url($pay_url)['query'];
- $retrun_data['order_no'] = $voucher_order['order_no'];
- $retrun_data['extend'] = $this->uid;
- $retrun_data['pay_url'] = $pay_url;
- $retrun_data['pay_query'] = $pay_query;
- break;
- case 'moyun':
- $obj = new Moyun();
- $notifyUrl = 'https://'.$_SERVER['HTTP_HOST'].'/api/Pay/moYunWalletNotify';//回调地址
- $return_url ='https://'.$_SERVER['HTTP_HOST']."/h5/pages/mine/mine?id={$order_id}&orderNo={$voucher_order['order_no']}";//回调地址
- $res = $obj->alipay('余额充值',$voucher_order['order_no'],$money,'',$notifyUrl,$return_url,$typecode);
- // if($this->uid == 73) var_dump($retrun_data);
- if(!isset($res['data']) || !$res['data']) throw new Exception($res['msg']);
- $retrun_data = $res['data'];
- break;
- case 'll':
- $notify_url = 'https://'.$_SERVER['HTTP_HOST'] . '/api/Pay/lianLianNotify';
- $return_url ='https://'.$_SERVER['HTTP_HOST']."/h5/pages/mine/mine?id={$order_id}&orderNo={$voucher_order['order_no']}";//回调地址
- $risk_item= risk_item($user,'订单支付',$from == 1 ? 16 : 10);
- $res= LianLianPay::cashierPay($voucher_order['order_no'],$money,$this->uid,$notify_url,$return_url,'余额充值',[[
- 'payee_id'=>OID_PARTNER,
- 'payee_type' => 'MERCHANT',
- 'payee_amount' => $money,
- ]],$risk_item);
- $retrun_data = $res['pay_result'];
- break;
- }
- Db::commit();
- }catch (\Exception $e){
- Db::rollback();
- DelRedisSetNx($this->request->action().$this->uid);
- $this->error($e->getMessage());
- }
- DelRedisSetNx($this->request->action().$this->uid);
- $this->success('ok',$retrun_data);
- }else{
- $this->error('服务器繁忙');
- }
- }
- /**
- * @title 云钱包余额充值
- * @desc 云钱包余额充值
- * @author Qc
- * @url /api/Recharge/cloudWalletVoucher
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:money type:int require:1 default:1 desc:充值金额
- * @param name:from type:int require:1 default1 desc:1:h5,2:app[Android],3:app[ios]
- * @return name:txn_seqno type:string default:0 desc:支付单号
- * @return name:total_amount type:string default:0 desc:金额
- * @return name:gateway_url type:string default:0 desc:支付地址
- */
- public function cloudWalletVoucher()
- {
- if(!checkAuth($this->uid)) $this->error('维护中.....');
- if (redisSetNx($this->request->action().$this->uid,3)) {
- $money = input('post.money',0);
- $from = input('post.from',1);
- if($money <=0 ) $this->error('充值金额有误!');
- $money = bcadd($money,0,2);
- $user = Db::name('store_member')->where('id',$this->uid)->find();
- //if(!$user['true_name'] || !$user['id_card']) $this->error('请实名认证,在进行订单支付');
- Db::startTrans();
- try{
- $voucher_order = [
- 'mid' => $this->uid ,
- 'total_price' => $money,
- 'order_no' =>get_order_sn(),
- 'pay_no' =>get_order_sn(),
- 'create_at' => date("Y-m-d H:i:s"),
- 'pay_type' => 'll',
- 'ext' => json_encode(['name'=>$user['true_name'],'phone'=>$user['phone'],'id_card'=>$user['id_card']])
- ];
- $order_id = Db::table('cloud_wallet_order')->insertGetId($voucher_order);
- $notify_url = 'https://'.$_SERVER['HTTP_HOST'] . '/api/Notify/cloudWalletNotify';
- $return_url ='https://'.$_SERVER['HTTP_HOST']."/h5/pages/mine/mine?id={$order_id}&orderNo={$voucher_order['order_no']}";//回调地址
- $risk_item= risk_item($user,'余额充值',$from == 1 ? 16 : 10);
- $res= LianLianPay::cloudWalletRecharge($voucher_order['order_no'],$money,$this->uid,$notify_url,$return_url,'余额充值',$risk_item);
- $retrun_data = $res['pay_result'];
- Db::commit();
- }catch (\Exception $e){
- Db::rollback();
- DelRedisSetNx($this->request->action().$this->uid);
- $this->error($e->getMessage());
- }
- DelRedisSetNx($this->request->action().$this->uid);
- $this->success('ok',$retrun_data);
- }else{
- $this->error('服务器繁忙');
- }
- }
- }
|