<?php
namespace app\api\model;

use app\api\controller\Send;
use think\Model;

/**
 * 分类
 */
class User extends Model
{
    use Send;

    /**
     * 表名,
     */
    protected $table = 'oauth_user';

    public function vali($json){
//        var_dump($json);die;
        if(empty($json->app_id)||empty($json->app_secret)||empty($json->type)||empty($json->entry_name)){
            return self::returnmsg(400);

        }
        if(count($json->app_id)>128||count($json->app_secret)>128||count($json->entry_name)>128){
            return self::returnmsg('402',[],[],'service_message','Data error.','参数长度超限');
        }
//        var_dump($json->type);die;
        switch ($json->type){
            case "web":
                break;
            case 'java':
                break;
            case "php":
            break;
            case 'android':
                break;
            case 'ios':
                break;
            default:
            return self::returnmsg('402',[],[],'service_message','Type error.','所属类型错误');
                break;

        }
        $status="app_id='{$json->app_id}'";
        $status_db=$this->where($status)->find();
        if($status_db){
            return self::returnmsg('402',[],[],'service_message','save error.','app_id已存在');
        }

            $data['app_id']=$json->app_id;
            $data['app_secret']=$json->app_secret;
            $data['type']=$json->type;
            $data['entry_name']=$json->entry_name;
            $data['possessor']=$json->possessor;
            $list=$this->insert($data);
            if($list){
                return true;
            }else{
                return self::returnmsg('402',[],[],'service_message','save error.','新增失败');
            }

    }

}