<?php

namespace App;

class Members extends Entity
{
    protected $fillable = [
        'nickname', 'real_name', 'phone_number', 'sex', 'pic', 'openid','points'
    ];

    const nav = '用户管理';

    const searchFields = [
        [
            'name' =>'nickname',
            'description' => '昵称',
            'type' => 'like'
        ],
        [
            'name' =>'phone_number',
            'description' => '手机号码',
            'type' => 'string'
        ]
    ];

    const columns = [
        'id' => 'ID',
        'nickname' => '昵称',
        'real_name' => '真实姓名',
        'phone_number' => '手机号',
        'sex_name' => '性别',
        'points' => '积分',
        'pic' => [
            'name' => '头像',
            'type' => 'image',
        ],
        'openid' => 'OPENID',
        'created_at' => '创建时间',
        'updated_at' => '更新时间'
    ];

    public function comments()
    {
        $this->hasMany(ProductsComments::class, 'members_id')->get();
    }

    public function incPoints($number) {
        $this->increment('points', $number);
    }

    public function getSexNameAttribute()
    {
        return $this->sex == 1 ? '男': "女";
    }
}
