sifangpay/app/ServicePay/LocalOrderServices.php

63 lines
1.9 KiB
PHP

<?php
namespace App\ServicePay;
use Yansongda\Pay\Pay;
class LocalOrderServices
{
use PayTrait;
public $must_input = ['money', 'goods_id', 'title'];
public function order($request)
{
//验证表单数据
$this->checkPost($request);
//通道检查
$this->checkGateway($request);
if (count(self::$errorArr) > 0) {
return $this->msg($this->errorFormat());
}
//获取用户
$this->user = user();
//设置订单数据
$this->setOrderData($request, 1);
//设置附加订单数据
$this->setOrderInfo($request, 1);
if ($this->createOrder()) {
$this->debugLog('选择通道是---' . $this->gateway['id'] . '方式是--' . $this->pay_method);
//支付通道配置,签名之类的
$this->pay_service->payConfig($this->pay_type);
$data = $this->orderTypeData();;
//发送支付请求
return $this->paySend($data);
} else {
return $this->msg(['error' => 1, 'msg' => '提交失败']);
}
}
public function orderTypeData()
{
switch ($this->pay_type) {
case 'weixin':
$order_pay = [
'out_trade_no' => self::$orderData['order_sn'],
'total_fee' => self::$orderData['order_money'] * 100,
'body' => self::$orderData['order_sn'] . '定制' //$request->input('title','测试数据')
];
break;
default:
$order_pay = [
'out_trade_no' => self::$orderData['order_sn'],
'total_amount' => self::$orderData['order_money'],
'subject' => self::$orderData['order_sn'] . '定制' //$request->input('title','测试数据')
];
break;
}
return $order_pay;
}
}