123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- namespace app\common\model;
- use think\Model;
- use app\common\model\User;
- use app\common\Enum\WithdrawEnum;
- class Withdraw extends Model
- {
- protected $name = 'shop_withdraw';
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $type = [
- 'withdraw_info' => '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');
- }
- }
|