初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace addons\epay\library;
|
||||
|
||||
use fast\Http;
|
||||
use think\Cache;
|
||||
use think\Session;
|
||||
use app\common\model\order\Status as OrderStatus;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\library\Auth;
|
||||
use think\Db;
|
||||
use app\common\model\User;
|
||||
use app\common\exception\Exception;
|
||||
/**
|
||||
* 余额
|
||||
*
|
||||
*/
|
||||
class Balance
|
||||
{
|
||||
protected $auth;
|
||||
protected $order;
|
||||
public function __construct()
|
||||
{
|
||||
$this->auth = new Auth();
|
||||
$this->order = new Order();
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额支付
|
||||
* @param $params 订单信息
|
||||
* @return bool
|
||||
*/
|
||||
public function pay($order){
|
||||
|
||||
$userInfo = $this->getOrderUser($order['order_no']);
|
||||
|
||||
if(!$userInfo){
|
||||
throw new Exception('获取用户信息失败');
|
||||
}
|
||||
|
||||
//余额不足
|
||||
if($userInfo['money'] < $order['amount']){
|
||||
throw new Exception('余额不足');
|
||||
}
|
||||
|
||||
$order = Db::transaction(function () use ($order,$userInfo) {
|
||||
//扣减余额
|
||||
User::money(($order['amount'] * -1), $userInfo['id'], "余额支付");
|
||||
// 支付后流程
|
||||
$notify = [
|
||||
'order_no' => $order['order_no'],
|
||||
'transaction_id' => '',
|
||||
'notify_time' => date('Y-m-d H:i:s'),
|
||||
'buyer_email' => $userInfo['id'],
|
||||
'pay_fee' => $order['amount'],
|
||||
'pay_type' => 'balance' // 支付方式
|
||||
];
|
||||
$notify['payment_json'] = json_encode($notify);
|
||||
|
||||
return Order::paySuccess($order, $notify);
|
||||
|
||||
});
|
||||
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取订单用户信息
|
||||
* @param $orderNo
|
||||
* @return false
|
||||
*/
|
||||
public function getOrderUser($orderNo)
|
||||
{
|
||||
$orderInfo = Order::orderNoGetOrder($orderNo);
|
||||
|
||||
if(!$orderInfo){
|
||||
return false;
|
||||
}
|
||||
|
||||
$userInfo = $this->auth->getUserinfo($orderInfo['user_id']);
|
||||
|
||||
return $userInfo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user