Skip to content

Commit

Permalink
feat(payment): 新增支付系统相关模型和迁移
Browse files Browse the repository at this point in the history
- 新增支付应用、支付渠道应用、支付商户等模型
- 创建支付单、退款单等迁移
- 添加支付状态、商户类型等枚举- 更新领域模型图
  • Loading branch information
liushoukun committed Nov 15, 2024
1 parent 7efab94 commit f2d6897
Show file tree
Hide file tree
Showing 23 changed files with 3,375 additions and 976 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"red-jasmine/support": "*",
"red-jasmine/filament-core": "*",
"red-jasmine/order": "*",
"red-jasmine/payment": "*",
"nunomaduro/collision": "^7.9",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.30",
Expand Down Expand Up @@ -63,7 +64,8 @@
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
}
}
3,985 changes: 3,103 additions & 882 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/payment/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"extra": {
"laravel": {
"providers": [
"PaymentPackageServiceProvider"
"RedJasmine\\Payment\\PaymentPackageServiceProvider"
],
"aliases": {

Expand Down
5 changes: 5 additions & 0 deletions packages/payment/config/red-jasmine-payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
return [
//

'tables' => [
'connection' => null,
'prefix' => 'jasmine_',
],


'channels' => [
'alipay' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
public function up() : void
{
Schema::create(config('red-jasmine-product.tables.prefix') . 'payment_apps', function (Blueprint $table) {
$table->id();


$table->unsignedBigInteger('id')->primary()->comment('ID');
$table->unsignedBigInteger('merchant_id')->comment('商户ID');
$table->string('name')->comment('名称');
$table->string('status')->comment('状态');
$table->string('remarks')->comment('备注');
$table->nullableMorphs('creator');
$table->nullableMorphs('updater');
$table->timestamps();

$table->softDeletes();
$table->comment('支付应用表');
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@
return new class extends Migration {
public function up() : void
{
Schema::create(config('red-jasmine-product.tables.prefix') . 'payment_channel_apps', function (Blueprint $table) {
Schema::create(config('red-jasmine-payment.tables.prefix') . 'payment_channel_apps', function (Blueprint $table) {
$table->id()->comment('ID');
$table->string('owner_type', 20)->comment('所属者类型');
$table->string('owner_id', 64)->comment('所属者UID');
$table->string('owner_nickname', 64)->nullable()->comment('所属者昵称');
$table->string('channel_type')->nullable()->comment('支付渠道');
$table->morphs('owner');
$table->string('channel')->nullable()->comment('支付渠道');
$table->string('channel_merchant_id')->nullable()->comment('渠道商户ID');
$table->string('channel_sub_merchant_id', 50)->nullable()->comment('渠道子商户ID');
$table->string('channel_app_id')->nullable()->comment('渠道应用ID');
$table->string('channel_app_sub_id')->nullable()->comment('渠道子商户应用ID');
$table->unsignedBigInteger('status')->default(1)->comment('状态');
$table->text('channel_public_key')->nullable()->comment('渠道公钥');
$table->text('channel_app_public_key')->nullable()->comment('应用公钥');
$table->text('channel_app_private_key')->nullable()->comment('应用私钥');
$table->text('channel_public_key')->nullable()->comment('渠道公钥');
$table->string('modes')->nullable()->comment('支持模式');

$table->string('status')->comment('状态');
$table->string('remarks')->comment('备注');
$table->nullableMorphs('creator');
$table->nullableMorphs('updater');
$table->timestamps();
$table->softDeletes();
$table->comment('支付渠道应用');
});
}

public function down() : void
{
Schema::dropIfExists(config('red-jasmine-product.tables.prefix') . 'payment_channel_apps');
Schema::dropIfExists(config('red-jasmine-payment.tables.prefix') . 'payment_channel_apps');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
return new class extends Migration {
public function up() : void
{
Schema::create(config('red-jasmine-product.tables.prefix') . 'payment_channels', function (Blueprint $table) {
Schema::create(config('red-jasmine-payment.tables.prefix') . 'payment_channels', function (Blueprint $table) {
$table->id();


Expand All @@ -18,6 +18,6 @@ public function up() : void

public function down() : void
{
Schema::dropIfExists(config('red-jasmine-product.tables.prefix') . 'payment_channels');
Schema::dropIfExists(config('red-jasmine-payment.tables.prefix') . 'payment_channels');
}
};
28 changes: 28 additions & 0 deletions packages/payment/database/migrations/create_payment_isvs_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up() : void
{
Schema::create(config('red-jasmine-payment.tables.prefix') . 'payment_isvs', function (Blueprint $table) {
$table->unsignedBigInteger('id')->primary()->comment('ID');
$table->unsignedBigInteger('merchant_id')->comment('商户ID');
$table->string('name')->comment('名称');
$table->string('status')->comment('状态');
$table->string('remarks')->comment('备注');
$table->nullableMorphs('creator');
$table->nullableMorphs('updater');
$table->timestamps();
$table->softDeletes();
$table->comment('支付应用表');
});
}

public function down() : void
{
Schema::dropIfExists(config('red-jasmine-payment.tables.prefix') . 'payment_isvs');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,30 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use RedJasmine\Payment\Domain\Models\Enums\MerchantTypeEnum;

return new class extends Migration {
public function up() : void
{
Schema::create(config('red-jasmine-product.tables.prefix') .'payment_merchants', function (Blueprint $table) {
$table->id();



Schema::create(config('red-jasmine-payment.tables.prefix') . 'payment_merchants', function (Blueprint $table) {
$table->unsignedBigInteger('id')->primary()->comment('商户ID');
$table->morphs('owner');
$table->string('name')->comment('名称');
$table->string('short_name')->comment('短名称');
$table->string('type')->comment(MerchantTypeEnum::comments('类型'));
$table->unsignedBigInteger('isv_id')->nullable()->comment('服务商ID');
$table->string('status')->comment('状态');
$table->string('remarks')->comment('备注');
$table->nullableMorphs('creator');
$table->nullableMorphs('updater');
$table->timestamps();
$table->softDeletes();
$table->comment('支付商户');
});
}

public function down() : void
{
Schema::dropIfExists(config('red-jasmine-product.tables.prefix') .'payment_merchants');
Schema::dropIfExists(config('red-jasmine-payment.tables.prefix') . 'payment_merchants');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,41 @@
return new class extends Migration {
public function up() : void
{
Schema::create(config('red-jasmine-product.tables.prefix') . 'payment_orders', function (Blueprint $table) {
Schema::create(config('red-jasmine-payment.tables.prefix') . 'payment_orders', function (Blueprint $table) {
$table->unsignedBigInteger('id')->primary()->comment('表ID');
$table->unsignedBigInteger('parent_id')->default(0)->comment('父级ID');

$table->string('owner_type', 20)->comment('所属者类型');
$table->string('owner_id', 64)->comment('所属者UID');
$table->string('owner_nickname', 64)->nullable()->comment('所属者昵称');
$table->unsignedBigInteger('merchant_id')->comment('商户ID');
$table->unsignedBigInteger('app_id')->comment('应用ID');
$table->unsignedBigInteger('isv_id')->default(0)->comment('服务商ID');


// 系统下应用类型
$table->unsignedBigInteger('app_id')->default(1)->comment('系统内应用ID');
$table->unsignedBigInteger('app_order_no')->nullable()->comment('应用订单号');
$table->string('app_order_type', 30)->nullable()->comment('应用订单类型');
$table->string('subject')->nullable()->comment('交易标题');
$table->string('description')->nullable()->comment('说明');
$table->string('currency')->comment('货币');
$table->decimal('amount')->default(0)->comment('金额');
$table->decimal('receipt_amount')->default(0)->comment('实收金额');
$table->decimal('invoice_amount')->default(0)->comment('开票金额');

// 支付渠道信息
$table->string('channel_type')->nullable()->comment('支付渠道');
$table->string('channel_merchant_id')->nullable()->comment('渠道商户ID');
$table->string('channel_sub_merchant_id', 50)->nullable()->comment('渠道子商户ID');
$table->string('channel_app_id')->nullable()->comment('渠道应用ID');
$table->string('channel_app_sub_id')->nullable()->comment('渠道子商户应用ID');
$table->string('channel')->nullable()->comment('支付渠道');
$table->string('channel_merchant_no')->comment('渠道商户号');
$table->string('channel_app_id')->comment('渠道商户号');
$table->string('channel_trade_no', 64)->nullable()->comment('渠道支付单号');
// 支付金额
$table->decimal('total_amount', 10)->default(0)->comment('交易金额');
$table->string('channel_payer_open_id', 64)->nullable()->comment('支付者');
$table->string('channel_payer_user_type')->nullable()->comment('支付者');



$table->string('merchant_order_no')->nullable()->comment('商户原始单号');


$table->decimal('tax_amount', 10)->default(0)->comment('手续费');
$table->decimal('pay_amount', 10)->default(0)->comment('实付金额');
$table->decimal('refund_amount', 10)->default(0)->comment('退款金额');
$table->decimal('channel_fee_ratio', 10)->default(0)->comment('渠道手续费率');
$table->decimal('channel_fee', 10)->default(0)->comment('渠道手续费');
// TODO 优惠
// 状态类
$table->unsignedTinyInteger('status')->default(0)->comment('支付状态');
$table->string('status')->comment('支付状态');

$table->timestamp('create_time')->nullable()->comment('创建时间');
$table->timestamp('expired_time')->nullable()->comment('过期时间');
Expand All @@ -51,11 +55,12 @@ public function up() : void
$table->json('pass_back_params')->nullable()->comment('回传参数');
$table->json('extends')->nullable()->comment('扩展参数');
$table->timestamps();
$table->comment('支付-支付单');
});
}

public function down() : void
{
Schema::dropIfExists(config('red-jasmine-product.tables.prefix') . 'payment_orders');
Schema::dropIfExists(config('red-jasmine-payment.tables.prefix') . 'payment_orders');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
return new class extends Migration {
public function up() : void
{
Schema::create(config('red-jasmine-product.tables.prefix') .'payment_refunds', function (Blueprint $table) {
Schema::create(config('red-jasmine-payment.tables.prefix') .'payment_refunds', function (Blueprint $table) {
$table->id();


$table->string('currency')->comment('货币');
$table->decimal('amount')->default(0)->comment('金额');

$table->timestamps();
$table->comment('支付-退款');
Expand All @@ -19,6 +20,6 @@ public function up() : void

public function down() : void
{
Schema::dropIfExists(config('red-jasmine-product.tables.prefix') .'payment_refunds');
Schema::dropIfExists(config('red-jasmine-payment0000000000000000.tables.prefix') .'payment_refunds');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up() : void
{
Schema::create('payment_transfers', function (Blueprint $table) {
$table->unsignedBigInteger('id')->primary()->comment('表ID');



$table->timestamps();
$table->comment('支付-转账');
});
}

public function down() : void
{
Schema::dropIfExists('payment_transfers');
}
};
30 changes: 30 additions & 0 deletions packages/payment/src/Domain/Models/Enums/MerchantTypeEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace RedJasmine\Payment\Domain\Models\Enums;

use RedJasmine\Support\Helpers\Enums\EnumsHelper;

/**
* 商户类型
*/
enum MerchantTypeEnum: string
{
use EnumsHelper;

// 普通商户
case GENERAL = 'general';

// 二级商户
case SUB = 'sub';


public static function lables() : array
{
return [
self::GENERAL->value => '普通商户',
self::SUB->value => '二级商户',
];
}


}
13 changes: 13 additions & 0 deletions packages/payment/src/Domain/Models/Model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace RedJasmine\Payment\Domain\Models;

abstract class Model extends \Illuminate\Database\Eloquent\Model
{

public function getConnectionName()
{
return config('red-jasmine-payment.tables.connection', null);
}

}
2 changes: 1 addition & 1 deletion packages/payment/src/Domain/Models/PaymentChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace RedJasmine\Payment\Domain\Models;

use Illuminate\Database\Eloquent\Model;

use Illuminate\Database\Eloquent\SoftDeletes;

class PaymentChannel extends Model
Expand Down
2 changes: 1 addition & 1 deletion packages/payment/src/Domain/Models/PaymentChannelApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace RedJasmine\Payment\Domain\Models;

use Illuminate\Database\Eloquent\Model;

use Illuminate\Database\Eloquent\SoftDeletes;

class PaymentChannelApp extends Model
Expand Down
21 changes: 21 additions & 0 deletions packages/payment/src/Domain/Models/PaymentIsv.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace RedJasmine\Payment\Domain\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class PaymentIsv extends Model
{

use SoftDeletes;




public function getTable() : string
{
return config('red-jasmine-payment.tables.prefix', 'jasmine_') . 'payment_isv';
}

}
2 changes: 1 addition & 1 deletion packages/payment/src/Domain/Models/PaymentMerchant.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace RedJasmine\Payment\Domain\Models;

use Illuminate\Database\Eloquent\Model;

use Illuminate\Database\Eloquent\SoftDeletes;

class PaymentMerchant extends Model
Expand Down
Loading

0 comments on commit f2d6897

Please sign in to comment.