160 lines
5.2 KiB
PHP
160 lines
5.2 KiB
PHP
<?php
|
|
/**
|
|
* Pay.php
|
|
* SaaSMall商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2023-2033 成都SAAS云科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.gobuysaas.com
|
|
* =========================================================
|
|
* @author : small
|
|
* @date : 2022.8.8
|
|
* @version : v5.0.0.1
|
|
*/
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\model\order\Order as OrderModel;
|
|
use app\model\system\Pay as PayModel;
|
|
use app\model\order\Config;
|
|
use app\model\system\PayBalance;
|
|
|
|
/**
|
|
* 支付控制器
|
|
*/
|
|
class Pay extends BaseApi
|
|
{
|
|
/**
|
|
* 支付信息
|
|
*/
|
|
public function info()
|
|
{
|
|
$out_trade_no = $this->params['out_trade_no'];
|
|
$pay = new PayModel();
|
|
$info = $pay->getPayInfo($out_trade_no)['data'] ?? [];
|
|
if (!empty($info)) {
|
|
if (isset($info['event']) && in_array($info['event'], ['OrderPayNotify', 'CashierOrderPayNotify'])) {
|
|
$order_model = new OrderModel();
|
|
$order_info = $order_model->getOrderInfo([['out_trade_no', '=', $out_trade_no]], 'order_id,order_type,member_id,order_status')['data'];
|
|
if ($order_info['order_status'] < 0) {
|
|
return $this->response($this->error('订单已关闭无法付款'));
|
|
}
|
|
if (!empty($order_info)) {
|
|
$info['order_id'] = $order_info['order_id'];
|
|
$info['order_type'] = $order_info['order_type'];
|
|
$trade_component_order_id = event('tradeComponentOrder', array_merge($this->params, $order_info), true);
|
|
if ($trade_component_order_id) {
|
|
$info['trade_component_order_id'] = $trade_component_order_id;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $this->response($this->success($info));
|
|
}
|
|
|
|
/**
|
|
* 支付调用
|
|
*/
|
|
public function pay()
|
|
{
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
$pay_type = $this->params['pay_type'];
|
|
$out_trade_no = $this->params['out_trade_no'];
|
|
$app_type = $this->params['app_type'];
|
|
$return_url = isset($this->params['return_url']) && !empty($this->params['return_url']) ? urldecode($this->params['return_url']) : null;
|
|
$scene = $this->params['scene'] ?? 0;
|
|
$is_balance = $this->params['is_balance'] ?? 0;
|
|
$hb_fq_num = $this->params['hb_fq_num'] ?? 0;
|
|
$pay = new PayModel();
|
|
$info = $pay->pay($pay_type, $out_trade_no, $app_type, $this->member_id, $return_url, $is_balance, $scene, $hb_fq_num);
|
|
return $this->response($info);
|
|
}
|
|
|
|
/**
|
|
* 支付方式
|
|
*/
|
|
public function type()
|
|
{
|
|
$pay = new PayModel();
|
|
$info = $pay->getPayType($this->params);
|
|
$temp = empty($info) ? [] : $info;
|
|
$type = implode(",", array_column($temp['data'], 'pay_type'));
|
|
if ($this->params['app_type'] == 'aliapp') { //临时处理
|
|
$type = 'alipay';
|
|
}
|
|
return $this->response(success(0, '', ['pay_type' => $type]));
|
|
}
|
|
|
|
public function typelist()
|
|
{
|
|
$pay = new PayModel();
|
|
$info = $pay->getPayType($this->params);
|
|
$temp = empty($info) ? [] : $info;
|
|
return $this->response($info);
|
|
}
|
|
|
|
/**
|
|
* 获取订单支付状态
|
|
*/
|
|
public function status()
|
|
{
|
|
$pay = new PayModel();
|
|
$out_trade_no = $this->params['out_trade_no'];
|
|
$res = $pay->getPayStatus($out_trade_no);
|
|
return $this->response($res);
|
|
}
|
|
|
|
/**
|
|
* 获取余额支付配置
|
|
*/
|
|
public function getBalanceConfig()
|
|
{
|
|
$config_model = new Config();
|
|
$res = $order_evaluate_config = $config_model->getBalanceConfig($this->site_id);
|
|
return $this->response($this->success($res['data']['value']));
|
|
}
|
|
|
|
/**
|
|
* 重置支付
|
|
*/
|
|
public function resetPay()
|
|
{
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
$out_trade_no = $this->params['out_trade_no'];
|
|
$pay = new PayModel();
|
|
|
|
return $this->response($this->success($out_trade_no));
|
|
//$result = $pay->resetPay(['out_trade_no' => $out_trade_no]);//临时屏蔽
|
|
return $this->response($result);
|
|
}
|
|
|
|
/**
|
|
* 会员付款码
|
|
*/
|
|
public function memberPayCode()
|
|
{
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
|
|
$data = (new PayBalance())->create(['member_id' => $this->member_id, 'site_id' => $this->site_id]);
|
|
return $this->response($data);
|
|
}
|
|
|
|
/**
|
|
* 查询会员付款码信息
|
|
* @return false|string
|
|
*/
|
|
public function memberPayInfo()
|
|
{
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
|
|
$auth_code = $this->params['auth_code'] ?? '';
|
|
|
|
$data = (new PayBalance())->getInfo([['member_id', '=', $this->member_id], ['site_id', '=', $this->site_id], ['auth_code', '=', $auth_code]], 'status,out_trade_no');
|
|
return $this->response($data);
|
|
}
|
|
}
|