| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 | 
							- <?php
 
- namespace app\api\controller;
 
- use app\common\controller\Api;
 
- use think\Db;
 
- use addons\epay\library\Service;
 
- /**
 
-  * 充值配置与充值订单
 
-  */
 
- class Pay extends Api
 
- {
 
-     protected $noNeedLogin = [];
 
-     protected $noNeedRight = ['*'];
 
-     //vip用的
 
-     public function vip_config(){
 
-         $list = Db::name('payvip_config')->order('weigh asc,id asc')->select();
 
-         $data['vipconfig'] = $list;
 
-         $data['vip_endtime'] = model('wallet')->getWallet($this->auth->id,'vip_endtime');
 
-         $data['is_vip'] = $data['vip_endtime'] > time() ? 1 : 0;
 
-         $data['avatar'] = localpath_to_netpath($this->auth->avatar);
 
-         $this->success('success',$data);
 
-     }
 
-     //vip用的,创建订单
 
-     public function vip_recharge(){
 
-         $rc_id = input('rc_id',0);
 
-         $pay_type = input('pay_type','wechat');
 
-         $platform = 'app';
 
-         $uid = $this->auth->id;
 
-         if(!$rc_id){
 
-             $this->error('请选择会员套餐');
 
-         }
 
-         if(!$this->user_auth_limit()){
 
-             $this->error('请先完成实名认证');
 
-         }
 
-         //赋值money
 
-         $recharge_config = Db::name('payvip_config')->where('id',$rc_id)->find();
 
-         $money = $recharge_config['money'];
 
-         if($money<=0)
 
-         {
 
-             $this->error('支付金额必须大于0');
 
-         }
 
-         if($money > 10000){
 
-             $this->error('支付金额太大');
 
-         }
 
-         //创建订单
 
-         $data = [];
 
-         $data['user_id'] = $uid;
 
-         $data['out_trade_no'] = createUniqueNo('P',$uid); // 数据库订单号加密
 
-         $data['order_amount'] = $money;
 
-         $data['createtime'] = time();
 
-         $data['pay_type'] = $pay_type;
 
-         $data['platform'] = $platform;
 
-         $data['order_status'] = 0;
 
-         $data['table_name'] = 'vip_recharge';
 
-         $data['table_id'] = 0;
 
-         $data['args'] = json_encode(['days'=>$recharge_config['days']]);
 
-         $orderid = Db::name('pay_order')->insertGetId($data);
 
- //        $openid = $this->auth->mini_openid;
 
-         //下单
 
-         $params = [
 
-             'type'         => $pay_type,
 
-             'orderid'      => $data['out_trade_no'],
 
-             'title'        => '支付订单',
 
-             'amount'       => $data['order_amount'],
 
-             'method'       => $platform,
 
- //            'openid'       => $openid,
 
-             'notifyurl' => config('pay_notify_url').'/api/notify/vip_notify_base/paytype/'.$pay_type,
 
-             'returnurl' => '',
 
-         ];
 
-         $res = Service::submitOrder($params);
 
-         if($pay_type == 'wechat'){
 
-             $this->success('success',json_decode($res,true));
 
-         }else{
 
-             $this->success('success',$res);
 
-         }
 
-     }
 
-     //金币充值
 
-     public function gold_config(){
 
-         $list = Db::name('paygold_webcon')->order('weigh asc,id asc')->select();
 
-         $data['goldconfig'] = $list;
 
-         $wallet = model('wallet')->getWallet($this->auth->id);
 
-         $data['wallet'] = $wallet;
 
-         $data['money_to_gold'] = config('site.money_to_gold');
 
-         $this->success('success',$data);
 
-     }
 
-     //充值金币 创建订单
 
-     public function gold_recharge(){
 
-         $rc_id     = input_post('rc_id',0);
 
-         $pay_type  = input_post('pay_type','wechat');
 
-         $platform  = 'app';
 
-         $freemoney = input_post('freemoney',0);
 
-         $uid = $this->auth->id;
 
-         if(!$rc_id && !$freemoney){
 
-             $this->error('请选择或填写充值金额');
 
-         }
 
-         if(!$this->user_auth_limit()){
 
-             $this->error('请先完成实名认证');
 
-         }
 
-         //赋值money
 
-         if($rc_id){
 
-             $recharge_config = Db::name('paygold_webcon')->where('id',$rc_id)->find();
 
-             $money = $recharge_config['money'] ?: 0;
 
-             $gold  = $recharge_config['gold'] ?: 0;
 
-         }
 
-         //自由输入覆盖
 
-         if(!empty($freemoney)){
 
-             $rc_id = 0;
 
-             $money = floatval($freemoney);
 
-             $bili = config('site.money_to_gold') ?: 10;
 
-             $gold  = bcmul($money,$bili,0);
 
-         }
 
-         //
 
-         if($money<=0)
 
-         {
 
-             $this->error('支付金额必须大于0');
 
-         }
 
-         if($money > 10000){
 
-             $this->error('支付金额太大');
 
-         }
 
-         //创建订单
 
-         $data = [];
 
-         $data['user_id'] = $uid;
 
-         $data['out_trade_no'] = createUniqueNo('P',$uid); // 数据库订单号加密
 
-         $data['order_amount'] = $money;
 
-         $data['createtime'] = time();
 
-         $data['pay_type'] = $pay_type;
 
-         $data['platform'] = $platform;
 
-         $data['order_status'] = 0;
 
-         $data['table_name'] = 'gold_recharge';
 
-         $data['table_id'] = 0;
 
-         $data['args'] = json_encode(['gold'=>$gold]);
 
-         $orderid = Db::name('pay_order')->insertGetId($data);
 
- //        $openid = $this->auth->mini_openid;
 
-         //下单
 
-         $params = [
 
-             'type'         => $pay_type,
 
-             'orderid'      => $data['out_trade_no'],
 
-             'title'        => '支付订单',
 
-             'amount'       => $data['order_amount'],
 
-             'method'       => $platform,
 
- //            'openid'       => $openid,
 
-             'notifyurl' => config('pay_notify_url').'/api/notify/recharge_notify_base/paytype/'.$pay_type,
 
-             'returnurl' => '',
 
-         ];
 
-         $res = Service::submitOrder($params);
 
-         if($pay_type == 'wechat'){
 
-             $this->success('success',json_decode($res,true));
 
-         }else{
 
-             $this->success('success',$res);
 
-         }
 
-     }
 
-     //收益兑换金币 配置
 
-     public function moneytogold_config(){
 
-         $list = Db::name('moneytogold_config')->order('weigh asc,id asc')->select();
 
-         $data['goldconfig'] = $list;
 
-         $wallet = model('wallet')->getWallet($this->auth->id);
 
-         $data['wallet'] = $wallet;
 
-         $data['money_to_gold'] = config('site.money_to_gold');
 
-         $data['remark'] = config('site.money_to_gold_rule');
 
-         $this->success('success',$data);
 
-     }
 
-     //收益兑换金币  兑换
 
-     public function moneytogold_exchange(){
 
-         $rc_id     = input_post('rc_id',0);
 
-         $freemoney = input_post('freemoney',0);
 
-         if(!$rc_id && !$freemoney){
 
-             $this->error('请选择或填写兑换金额');
 
-         }
 
-         $uid = $this->auth->id;
 
-         //赋值money
 
-         if($rc_id){
 
-             $recharge_config = Db::name('moneytogold_config')->where('id',$rc_id)->find();
 
-             $money = $recharge_config['money'] ?: 0;
 
-             $gold  = $recharge_config['gold'] ?: 0;
 
-         }
 
-         //自由输入覆盖
 
-         if(!empty($freemoney)){
 
-             $rc_id = 0;
 
-             $money = floatval($freemoney);
 
-             $bili = config('site.money_to_gold') ?: 10;
 
-             $gold  = bcmul($money,$bili,0);
 
-         }
 
-         //
 
-         if($money<=0)
 
-         {
 
-             $this->error('兑换金额必须大于0');
 
-         }
 
-         //扣除money
 
-         $rs_wallet = model('Wallet')->lockChangeAccountRemain($uid,'money',-$money,21, '收益兑换金币');
 
-         if($rs_wallet['status']===false)
 
-         {
 
-             Db::rollback();
 
-             $this->error($rs_wallet['msg']);
 
-         }
 
-         //增加gold
 
-         $rs_wallet = model('Wallet')->lockChangeAccountRemain($uid,'gold',$gold,22, '收益兑换金币',$rs_wallet['log_table'],$rs_wallet['log_id']);
 
-         if($rs_wallet['status']===false)
 
-         {
 
-             Db::rollback();
 
-             $this->error($rs_wallet['msg']);
 
-         }
 
-         Db::commit();
 
-         $this->success();
 
-     }
 
- }
 
 
  |