mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-26 12:23:06 +08:00
* 更新H5支付方式 * Merge remote-tracking branch 'remotes/gitee/master' into develop * !19 v1.2.0阶段性合并 * update app/Http/Admin/Controllers/UploadController.php. * Merge branch 'develop' of https://gitee.com/koogua/course-tencent-cloud * Merge branch 'master' of https://gitee.com/koogua/course-tencent-cloud * add LICENSE. * 删除文件 LICENSE * !14 修正点击退款404 * !13 修正退款项目空白以及弹窗自适应 * !12 修正退款项目空白以及弹窗自适应 * Merge branch 'master' of https://gitee.com/koogua/course-tencent-cloud * !9 修正插入数据不一致以及后台菜单参数类型报错 * !7 纠正迁移文件和代码实际使用字段不一致 * Merge branch 'master' of https://gitee.com/koogua/course-tencent-cloud * !6 develop->master 1.1.0
126 lines
3.1 KiB
PHP
126 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Api\Services;
|
|
|
|
use App\Models\Client as ClientModel;
|
|
use App\Models\Trade as TradeModel;
|
|
use App\Services\Logic\OrderTrait;
|
|
use App\Services\Logic\TradeTrait;
|
|
use App\Services\Pay\Alipay;
|
|
use App\Services\Pay\Wxpay;
|
|
use App\Validators\Client as ClientValidator;
|
|
use App\Validators\Trade as TradeValidator;
|
|
|
|
class Trade extends Service
|
|
{
|
|
|
|
use OrderTrait;
|
|
use TradeTrait;
|
|
|
|
public function createH5Trade()
|
|
{
|
|
$post = $this->request->getPost();
|
|
|
|
$validator = new ClientValidator();
|
|
|
|
$platform = $this->getPlatform();
|
|
|
|
$validator->checkH5Platform($platform);
|
|
|
|
$order = $this->checkOrderBySn($post['order_sn']);
|
|
|
|
$user = $this->getLoginUser();
|
|
|
|
$validator = new TradeValidator();
|
|
|
|
$channel = $validator->checkChannel($post['channel']);
|
|
|
|
$trade = new TradeModel();
|
|
|
|
$trade->subject = $order->subject;
|
|
$trade->amount = $order->amount;
|
|
$trade->channel = $channel;
|
|
$trade->order_id = $order->id;
|
|
$trade->owner_id = $user->id;
|
|
|
|
$trade->create();
|
|
|
|
$redirect = '';
|
|
|
|
if ($trade->channel == TradeModel::CHANNEL_ALIPAY) {
|
|
$alipay = new Alipay();
|
|
$response = $alipay->wap($trade);
|
|
$redirect = $response ? $response->getTargetUrl() : '';
|
|
} elseif ($trade->channel == TradeModel::CHANNEL_WXPAY) {
|
|
$wxpay = new Wxpay();
|
|
$response = $wxpay->wap($trade);
|
|
$redirect = $response ? $response->getTargetUrl() : '';
|
|
}
|
|
|
|
$payment = ['redirect' => $redirect];
|
|
|
|
return [
|
|
'trade' => $trade,
|
|
'payment' => $payment,
|
|
];
|
|
}
|
|
|
|
public function createMpTrade()
|
|
{
|
|
$post = $this->request->getPost();
|
|
|
|
$validator = new ClientValidator();
|
|
|
|
$platform = $this->getPlatform();
|
|
|
|
$platform = $validator->checkMpPlatform($platform);
|
|
|
|
$order = $this->checkOrderBySn($post['order_sn']);
|
|
|
|
$user = $this->getLoginUser();
|
|
|
|
$channel = TradeModel::CHANNEL_WXPAY;
|
|
|
|
if ($platform == ClientModel::TYPE_MP_ALIPAY) {
|
|
$channel = TradeModel::CHANNEL_ALIPAY;
|
|
} elseif ($platform == ClientModel::TYPE_MP_WEIXIN) {
|
|
$channel = TradeModel::CHANNEL_WXPAY;
|
|
}
|
|
|
|
$trade = new TradeModel();
|
|
|
|
$trade->subject = $order->subject;
|
|
$trade->amount = $order->amount;
|
|
$trade->channel = $channel;
|
|
$trade->order_id = $order->id;
|
|
$trade->owner_id = $user->id;
|
|
|
|
$trade->create();
|
|
|
|
$response = null;
|
|
|
|
if ($post['channel'] == TradeModel::CHANNEL_ALIPAY) {
|
|
$alipay = new Alipay();
|
|
$buyerId = '';
|
|
$response = $alipay->mini($trade, $buyerId);
|
|
} elseif ($post['channel'] == TradeModel::CHANNEL_WXPAY) {
|
|
$wxpay = new Wxpay();
|
|
$openId = '';
|
|
$response = $wxpay->mini($trade, $openId);
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
|
|
public function createAppTrade()
|
|
{
|
|
|
|
}
|
|
|
|
protected function getPlatform()
|
|
{
|
|
return $this->request->getHeader('X-Platform');
|
|
}
|
|
|
|
}
|