1 line
1.8 KiB
PHP
Executable File
1 line
1.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\user\controller;
|
|
|
|
use app\user\model\User as UserModel;
|
|
use app\user\model\Setting as SettingModel;
|
|
use app\user\model\Record as RecordModel;
|
|
use hema\wechat\Pay as WxPay;
|
|
use think\facade\View;
|
|
use think\facade\Cache;
|
|
|
|
/**
|
|
* 钱包余额管理
|
|
*/
|
|
class Money extends Controller
|
|
{
|
|
|
|
/**
|
|
* 用户钱包
|
|
*/
|
|
public function index()
|
|
{
|
|
$user = UserModel::get($this->user_id);
|
|
View::assign('money',$user['money']);
|
|
return View::fetch('index');
|
|
}
|
|
/**
|
|
* 商户充值
|
|
*/
|
|
public function recharge($money)
|
|
{
|
|
$order_no = order_no();
|
|
Cache::set($order_no, [
|
|
'mode' => 10,//充值
|
|
'type' => 30,//微信
|
|
'order_no' => $order_no,
|
|
'money' => $money,
|
|
'remark' => '扫码充值',
|
|
'user_id' => $this->user_id
|
|
], 7200);
|
|
$values = SettingModel::getItem('webpay');
|
|
$wx = new WxPay($values['wx']);
|
|
if(!$code_url = $wx->native($order_no,$money,'api/notify/native','商户充值')){
|
|
return $this->renderError($wx->getError());
|
|
}
|
|
$data = [
|
|
'money' => $money,
|
|
'code_url' => $code_url,
|
|
'order_no' => $order_no
|
|
];
|
|
return $this->renderSuccess('','',$data);
|
|
}
|
|
/**
|
|
* 支付流水
|
|
*/
|
|
public function log()
|
|
{
|
|
$model = new RecordModel;
|
|
$list = $model->getList(['user_id' => $this->user_id]);
|
|
return View::fetch('log', compact('list'));
|
|
}
|
|
/**
|
|
* 充值成功后跳转 - 需要在微信支付商户中心设置Native支付回调链接
|
|
* 链接地址:你的域名/user/money/ok
|
|
*/
|
|
public function ok($order_no='')
|
|
{
|
|
if(!Cache::get($order_no)){
|
|
return $this->renderSuccess('支付结束');
|
|
}
|
|
return $this->renderError('支付中');
|
|
}
|
|
|
|
} |