<?php

namespace app\model;

use think\Model;

class MemberCategory extends Model
{

    protected $connection = 'mysql';

    protected $pk = 'id';

    protected $name = 'member_category';


    function getdatalist()
    {
        $ptypeArray =  $this->where(['weid' => weid()])->select()->toArray();
        return $ptypeArray;
    }

    public static function getLevel($id = '')
    {
        $ret = self::find($id);
        if (!empty($ret)) {
            $ret = $ret->toArray();
        }
        return $ret['title'];
    }
    public static function getarray()
    {
        $data = self::where(['weid' => weid()])->order('id desc')->select()->toArray();
        if (!empty($data))
            foreach ($data as $vo) {
                $datalist[$vo['id']] = $vo['title'];
            }
        else
            $datalist['0'] = '可添会员类别';

        return $datalist;
    }

    public static function getpcarray()
    {
        $data = self::field('id,title')->where(['weid' => weid()])->select()->toArray();
        $datalist = [];
        foreach ($data as $key => $vo) {
            $datalist[$key]['val'] = $vo['id'];
			$datalist[$key]['key'] = $vo['title'];
        }
        return $datalist;
    }

    public static function getone()
    {
        $ret = self::where(['weid' => weid()])->order('id asc')->find();

		if (!empty($ret)) {
			$ret = $ret->toArray();
		}

        return $ret;
    }
}
