'json' ]; // 追加属性 protected $append = [ 'status_text', 'status_style', 'charge_rate_format', 'withdraw_info_hidden', 'withdraw_type_text', 'wechat_transfer_state_text', ]; // 注:微信转账状态和可退还佣金状态已移至 WithdrawEnum 枚举类 public function statusList() { return WithdrawEnum::getStatusList(); } public function withdrawTypeList() { return WithdrawEnum::getTypeList(); } /** * 获取微信转账状态列表 */ public function wechatTransferStateList() { return WithdrawEnum::getWechatTransferStateList(); } /** * 获取可以安全退还佣金的状态列表 */ public function canCancelStates() { return WithdrawEnum::getCanCancelStates(); } /** * 检查是否可以退还佣金 */ public function canRefundCommission() { return in_array($this->wechat_transfer_state, WithdrawEnum::getCanCancelStates()); } /** * 状态获取器 */ public function getStatusTextAttr($value, $data) { $value = $value ?: ($data['status'] ?? null); return WithdrawEnum::getStatusName($value); } /** * 状态样式获取器 */ public function getStatusStyleAttr($value, $data) { $value = $value ?: ($data['status'] ?? null); return WithdrawEnum::getStatusStyle($value); } /** * 类型获取器 */ public function getWithdrawTypeTextAttr($value, $data) { $value = $value ?: ($data['withdraw_type'] ?? null); return WithdrawEnum::getTypeName($value); } public function getWechatTransferStateTextAttr($value, $data) { $value = $value ?: ($data['wechat_transfer_state'] ?? null); return WithdrawEnum::getWechatTransferStateName($value); } public function getChargeRateFormatAttr($value, $data) { $value = $value ?: ($data['charge_rate'] ?? null); // 安全处理手续费率格式化 if (is_numeric($value) && $value !== null && $value !== '') { return bcmul((string)$value, '100', 1) . '%'; } else { return '0%'; } } public function getWithdrawInfoHiddenAttr($value, $data) { $withdraw_info = $value ?: ($this->withdraw_info ?? null); foreach ($withdraw_info as $key => &$info) { if (in_array($key, ['微信用户', '真实姓名'])) { $info = string_hide($info, 2); } elseif (in_array($key, ['银行卡号', '支付宝账户', '微信ID'])) { $info = account_hide($info); } } return $withdraw_info; } public function user() { return $this->belongsTo(User::class, 'user_id', 'id')->field('id, username, nickname, avatar, total_consume'); } }