MoneyLog.php 1.5 KB
<?php

namespace app\api\model;

use think\Model;


class MoneyLog extends Model
{


    // 表名
    protected $name = 'user_money_log';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'commission_type_text',
    ];


    public function getTypeList()
    {
        return ['get' => '获得佣金', 'out' => '退回佣金'];
    }

    public function getCommissionTypeList()
    {
        return ['1' => '直推', '2' => '推广'];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list  = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getCreateTimeAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function getCommissionTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['commission_type']) ? $data['commission_type'] : '');
        $list  = $this->getCommissionTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}