| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- namespace App\Module\UrsPromotion\Models;
- use UCore\ModelCore;
- /**
- * URS合伙人分红记录模型
- *
- * field start
- * @property int $id 主键ID
- * @property \Carbon\Carbon $dividend_date 分红日期
- * @property float $total_fee_amount 当日总手续费金额
- * @property float $dividend_amount 分红总金额(总手续费的20%)
- * @property int $partner_count 合伙人数量
- * @property float $per_partner_amount 每个合伙人分红金额
- * @property int $transfer_app_id 转账应用ID
- * @property string $status 状态:pending待处理,processing处理中,completed已完成,failed失败
- * @property string $error_message 错误信息
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- *
- * relation start
- * @property \App\Module\Transfer\Models\TransferApp $transferApp 转账应用
- * @property \Illuminate\Database\Eloquent\Collection|\App\Module\UrsPromotion\Models\UrsPartnerDividendDetail[] $details 分红详情
- * relation end
- */
- class UrsPartnerDividendRecord extends ModelCore
- {
- /**
- * 表名
- */
- protected $table = 'urs_promotion_partner_dividend_records';
- // attrlist start
- protected $fillable = [
- 'id',
- 'dividend_date',
- 'total_fee_amount',
- 'dividend_amount',
- 'partner_count',
- 'per_partner_amount',
- 'transfer_app_id',
- 'status',
- 'error_message',
- ];
- // attrlist end
- /**
- * 属性类型转换
- */
- protected $casts = [
- 'id' => 'integer',
- 'dividend_date' => 'date',
- 'total_fee_amount' => 'decimal:10',
- 'dividend_amount' => 'decimal:10',
- 'partner_count' => 'integer',
- 'per_partner_amount' => 'decimal:10',
- 'transfer_app_id' => 'integer',
- 'status' => 'string',
- 'error_message' => 'string',
- 'created_at' => 'datetime',
- 'updated_at' => 'datetime',
- ];
- /**
- * 隐藏字段
- */
- protected $hidden = [];
- // 状态常量
- const STATUS_PENDING = 'pending';
- const STATUS_PROCESSING = 'processing';
- const STATUS_COMPLETED = 'completed';
- const STATUS_FAILED = 'failed';
- /**
- * 获取所有状态
- */
- public static function getStatuses(): array
- {
- return [
- self::STATUS_PENDING => '待处理',
- self::STATUS_PROCESSING => '处理中',
- self::STATUS_COMPLETED => '已完成',
- self::STATUS_FAILED => '失败',
- ];
- }
- /**
- * 获取状态名称
- */
- public function getStatusNameAttribute(): string
- {
- return self::getStatuses()[$this->status] ?? '未知';
- }
- /**
- * 关联转账应用
- */
- public function transferApp()
- {
- return $this->belongsTo(\App\Module\Transfer\Models\TransferApp::class, 'transfer_app_id');
- }
- /**
- * 关联分红详情
- */
- public function details()
- {
- return $this->hasMany(UrsPartnerDividendDetail::class, 'dividend_record_id');
- }
- /**
- * 根据日期获取分红记录
- */
- public static function getByDate(string $date): ?self
- {
- return self::where('dividend_date', $date)->first();
- }
- /**
- * 检查指定日期是否已经分红
- */
- public static function isDividendProcessed(string $date): bool
- {
- return self::where('dividend_date', $date)
- ->whereIn('status', [self::STATUS_COMPLETED, self::STATUS_PROCESSING])
- ->exists();
- }
- /**
- * 获取成功分红的记录数量
- */
- public static function getCompletedCount(): int
- {
- return self::where('status', self::STATUS_COMPLETED)->count();
- }
- /**
- * 获取总分红金额
- */
- public static function getTotalDividendAmount(): string
- {
- return self::where('status', self::STATUS_COMPLETED)
- ->sum('dividend_amount');
- }
- }
|