chore: init saasshop repo + sql migrations runner + gitee go
This commit is contained in:
49
app/Models/Admin.php
Normal file
49
app/Models/Admin.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Admin extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'merchant_id', 'name', 'email', 'phone', 'password', 'role', 'status', 'last_login_at',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password', 'remember_token',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'last_login_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function merchant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Merchant::class, 'merchant_id');
|
||||
}
|
||||
|
||||
public function merchantId(): ?int
|
||||
{
|
||||
return $this->merchant_id ? (int) $this->merchant_id : null;
|
||||
}
|
||||
|
||||
public function isPlatformAdmin(): bool
|
||||
{
|
||||
return $this->merchantId() === null;
|
||||
}
|
||||
|
||||
public function isMerchantAdmin(): bool
|
||||
{
|
||||
return $this->merchantId() !== null;
|
||||
}
|
||||
|
||||
public function platformLabel(): string
|
||||
{
|
||||
return $this->isPlatformAdmin() ? 'platform' : 'merchant';
|
||||
}
|
||||
}
|
||||
23
app/Models/ChannelConfig.php
Normal file
23
app/Models/ChannelConfig.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ChannelConfig extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'channel_code', 'channel_name', 'channel_type', 'status', 'entry_path',
|
||||
'supports_login', 'supports_payment', 'supports_share', 'sort', 'settings', 'remark',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'supports_login' => 'boolean',
|
||||
'supports_payment' => 'boolean',
|
||||
'supports_share' => 'boolean',
|
||||
'settings' => 'array',
|
||||
];
|
||||
}
|
||||
50
app/Models/Merchant.php
Normal file
50
app/Models/Merchant.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Merchant extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'merchants';
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'slug', 'domain', 'contact_name', 'contact_phone', 'contact_email',
|
||||
'plan', 'status', 'trial_ends_at', 'activated_at', 'settings',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'trial_ends_at' => 'datetime',
|
||||
'activated_at' => 'datetime',
|
||||
'settings' => 'array',
|
||||
];
|
||||
|
||||
public function admins(): HasMany
|
||||
{
|
||||
return $this->hasMany(Admin::class, 'merchant_id');
|
||||
}
|
||||
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(User::class, 'merchant_id');
|
||||
}
|
||||
|
||||
public function products(): HasMany
|
||||
{
|
||||
return $this->hasMany(Product::class, 'merchant_id');
|
||||
}
|
||||
|
||||
public function orders(): HasMany
|
||||
{
|
||||
return $this->hasMany(Order::class, 'merchant_id');
|
||||
}
|
||||
|
||||
public function categories(): HasMany
|
||||
{
|
||||
return $this->hasMany(ProductCategory::class, 'merchant_id');
|
||||
}
|
||||
}
|
||||
30
app/Models/OauthAccount.php
Normal file
30
app/Models/OauthAccount.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class OauthAccount extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id', 'merchant_id', 'platform', 'provider', 'openid', 'unionid', 'app_id', 'nickname', 'avatar', 'raw_payload',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'raw_payload' => 'array',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function merchant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Merchant::class, 'merchant_id');
|
||||
}
|
||||
}
|
||||
50
app/Models/Order.php
Normal file
50
app/Models/Order.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Order extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'merchant_id', 'user_id', 'order_no', 'status', 'platform', 'payment_channel', 'payment_status', 'device_type',
|
||||
'product_amount', 'discount_amount', 'shipping_amount', 'pay_amount', 'buyer_name', 'buyer_phone', 'buyer_email',
|
||||
'remark', 'paid_at', 'shipped_at', 'completed_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'product_amount' => 'decimal:2',
|
||||
'discount_amount' => 'decimal:2',
|
||||
'shipping_amount' => 'decimal:2',
|
||||
'pay_amount' => 'decimal:2',
|
||||
'paid_at' => 'datetime',
|
||||
'shipped_at' => 'datetime',
|
||||
'completed_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function merchant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Merchant::class, 'merchant_id');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(OrderItem::class);
|
||||
}
|
||||
|
||||
public function scopeForMerchant(Builder $query, int $merchantId): Builder
|
||||
{
|
||||
return $query->where('merchant_id', $merchantId);
|
||||
}
|
||||
}
|
||||
43
app/Models/OrderItem.php
Normal file
43
app/Models/OrderItem.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class OrderItem extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'merchant_id', 'order_id', 'product_id', 'product_title', 'product_sku', 'product_price', 'quantity', 'line_total_amount', 'snapshot',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'product_price' => 'decimal:2',
|
||||
'line_total_amount' => 'decimal:2',
|
||||
'snapshot' => 'array',
|
||||
];
|
||||
|
||||
public function merchant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Merchant::class, 'merchant_id');
|
||||
}
|
||||
|
||||
public function order(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Order::class);
|
||||
}
|
||||
|
||||
public function product(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
public function scopeForMerchant(Builder $query, int $merchantId): Builder
|
||||
{
|
||||
return $query->where('merchant_id', $merchantId);
|
||||
}
|
||||
}
|
||||
21
app/Models/PaymentConfig.php
Normal file
21
app/Models/PaymentConfig.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PaymentConfig extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'payment_code', 'payment_name', 'provider', 'status', 'is_sandbox', 'supports_refund', 'settings', 'remark',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_sandbox' => 'boolean',
|
||||
'supports_refund' => 'boolean',
|
||||
'settings' => 'array',
|
||||
];
|
||||
}
|
||||
33
app/Models/Plan.php
Normal file
33
app/Models/Plan.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Plan extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'code', 'name', 'billing_cycle', 'price', 'list_price', 'status', 'sort', 'description', 'settings', 'published_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'price' => 'decimal:2',
|
||||
'list_price' => 'decimal:2',
|
||||
'settings' => 'array',
|
||||
'published_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function subscriptions(): HasMany
|
||||
{
|
||||
return $this->hasMany(SiteSubscription::class);
|
||||
}
|
||||
|
||||
public function platformOrders(): HasMany
|
||||
{
|
||||
return $this->hasMany(PlatformOrder::class);
|
||||
}
|
||||
}
|
||||
53
app/Models/PlatformOrder.php
Normal file
53
app/Models/PlatformOrder.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PlatformOrder extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'merchant_id', 'plan_id', 'site_subscription_id', 'created_by_admin_id', 'order_no', 'order_type', 'status',
|
||||
'payment_status', 'payment_channel', 'plan_name', 'billing_cycle', 'period_months', 'quantity', 'list_amount',
|
||||
'discount_amount', 'payable_amount', 'paid_amount', 'placed_at', 'paid_at', 'activated_at', 'cancelled_at',
|
||||
'refunded_at', 'plan_snapshot', 'meta', 'remark',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'list_amount' => 'decimal:2',
|
||||
'discount_amount' => 'decimal:2',
|
||||
'payable_amount' => 'decimal:2',
|
||||
'paid_amount' => 'decimal:2',
|
||||
'placed_at' => 'datetime',
|
||||
'paid_at' => 'datetime',
|
||||
'activated_at' => 'datetime',
|
||||
'cancelled_at' => 'datetime',
|
||||
'refunded_at' => 'datetime',
|
||||
'plan_snapshot' => 'array',
|
||||
'meta' => 'array',
|
||||
];
|
||||
|
||||
public function merchant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Merchant::class, 'merchant_id');
|
||||
}
|
||||
|
||||
public function plan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Plan::class);
|
||||
}
|
||||
|
||||
public function siteSubscription(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(SiteSubscription::class);
|
||||
}
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Admin::class, 'created_by_admin_id');
|
||||
}
|
||||
}
|
||||
44
app/Models/Product.php
Normal file
44
app/Models/Product.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Product extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'merchant_id', 'category_id', 'title', 'slug', 'sku', 'summary', 'content', 'price', 'original_price', 'stock', 'status', 'images',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'price' => 'decimal:2',
|
||||
'original_price' => 'decimal:2',
|
||||
'images' => 'array',
|
||||
];
|
||||
|
||||
public function merchant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Merchant::class, 'merchant_id');
|
||||
}
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ProductCategory::class, 'category_id');
|
||||
}
|
||||
|
||||
public function orderItems(): HasMany
|
||||
{
|
||||
return $this->hasMany(OrderItem::class);
|
||||
}
|
||||
|
||||
public function scopeForMerchant(Builder $query, int $merchantId): Builder
|
||||
{
|
||||
return $query->where('merchant_id', $merchantId);
|
||||
}
|
||||
}
|
||||
33
app/Models/ProductCategory.php
Normal file
33
app/Models/ProductCategory.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class ProductCategory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'merchant_id', 'name', 'slug', 'status', 'sort', 'description',
|
||||
];
|
||||
|
||||
public function merchant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Merchant::class, 'merchant_id');
|
||||
}
|
||||
|
||||
public function products(): HasMany
|
||||
{
|
||||
return $this->hasMany(Product::class, 'category_id');
|
||||
}
|
||||
|
||||
public function scopeForMerchant(Builder $query, int $merchantId): Builder
|
||||
{
|
||||
return $query->where('merchant_id', $merchantId);
|
||||
}
|
||||
}
|
||||
37
app/Models/ProductImportHistory.php
Normal file
37
app/Models/ProductImportHistory.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ProductImportHistory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'scope',
|
||||
'merchant_id',
|
||||
'admin_id',
|
||||
'file_name',
|
||||
'success_count',
|
||||
'failed_count',
|
||||
'failure_file',
|
||||
'imported_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'imported_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function merchant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Merchant::class);
|
||||
}
|
||||
|
||||
public function admin(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Admin::class);
|
||||
}
|
||||
}
|
||||
44
app/Models/SiteSubscription.php
Normal file
44
app/Models/SiteSubscription.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class SiteSubscription extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'merchant_id', 'plan_id', 'status', 'source', 'subscription_no', 'plan_name', 'billing_cycle', 'period_months',
|
||||
'amount', 'starts_at', 'ends_at', 'trial_ends_at', 'activated_at', 'cancelled_at', 'snapshot', 'meta',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'amount' => 'decimal:2',
|
||||
'starts_at' => 'datetime',
|
||||
'ends_at' => 'datetime',
|
||||
'trial_ends_at' => 'datetime',
|
||||
'activated_at' => 'datetime',
|
||||
'cancelled_at' => 'datetime',
|
||||
'snapshot' => 'array',
|
||||
'meta' => 'array',
|
||||
];
|
||||
|
||||
public function merchant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Merchant::class, 'merchant_id');
|
||||
}
|
||||
|
||||
public function plan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Plan::class);
|
||||
}
|
||||
|
||||
public function platformOrders(): HasMany
|
||||
{
|
||||
return $this->hasMany(PlatformOrder::class);
|
||||
}
|
||||
}
|
||||
19
app/Models/SystemConfig.php
Normal file
19
app/Models/SystemConfig.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SystemConfig extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'config_key', 'config_name', 'config_value', 'value_type', 'autoload', 'group', 'remark',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'autoload' => 'boolean',
|
||||
];
|
||||
}
|
||||
53
app/Models/User.php
Normal file
53
app/Models/User.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
protected $fillable = [
|
||||
'merchant_id', 'name', 'email', 'phone', 'password', 'status',
|
||||
'register_source', 'last_login_source', 'wechat_openid', 'wechat_unionid', 'mini_openid',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
public function merchant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Merchant::class, 'merchant_id');
|
||||
}
|
||||
|
||||
public function orders(): HasMany
|
||||
{
|
||||
return $this->hasMany(Order::class);
|
||||
}
|
||||
|
||||
public function oauthAccounts(): HasMany
|
||||
{
|
||||
return $this->hasMany(OauthAccount::class);
|
||||
}
|
||||
|
||||
public function scopeForMerchant(Builder $query, int $merchantId): Builder
|
||||
{
|
||||
return $query->where('merchant_id', $merchantId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user