123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace app\api\controller;
- use app\common\library\Shande;
- use app\common\library\ShandeRapid;
- use think\Db;
- use think\Exception;
- /**
- * @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:杉德快捷支付
- * @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:正书
- */
- public function voucher()
- {
- // if($this->uid != 73) $this->error('暂未开通');
- if (redisSetNx($this->request->action().$this->uid,3)) {
- $money = input('post.money',0);
- $pay_type = input('post.pay_type','sd_rapid');
- 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' => $pay_type
- ];
- $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;
- }
- 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('服务器繁忙');
- }
- }
- }
|