1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace app\api\controller;
- use app\common\library\Shande;
- 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:充值金额
- * @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 (redisSetNx($this->request->action().$this->uid,3)) {
- $money = input('post.money',0);
- if($money <=0 ) $this->error('充值金额有误!');
- $money = bcadd($money,0,2);
- $user = Db::name('store_member')->where('id',$this->uid)->find();
- 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' => 'sd'
- ];
- $order_id = Db::table('store_recharge_order')->insertGetId($voucher_order);
- $notify_url = $this->request->root(true) . '/api/Pay/walletNotify';
- $client = new Shande();
- $total_fee = $money*100;
- $lenth = strlen($total_fee);
- $total_fee = get0number($lenth).$total_fee;
- $result = $client->orderPay($voucher_order['pay_no'],$total_fee,'订单充值',$notify_url,'https://'.$_SERVER['HTTP_HOST'].'/h5/pages/mine/mine',$user['bank_num']);
- $retrun_data['order_no'] = $voucher_order['pay_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'].'请重新下单');
- 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('服务器繁忙');
- }
- }
- }
|