<?php
namespace App\Services;

use Illuminate\Support\Facades\DB;

class PersonService
{
    public function checkRegister($arr){
        $openid=$arr['openid'];
        $c=DB::table('persons')->where(['openid'=>$openid])->get();
        if(count($c)){
            return [true,$c[0]->id];
        }else{
            return  [false];
        }
    }
    //注册
    public function Register($arr){
        $result=array();
        $c= $this->checkRegister(['openid'=>$arr['openid']]);
        if($c){
            $result['status']=false;
            $result['msg']='已注册过，无需进行此操作';
        }else{
            $i=DB::table('persons')->insert([
                'name' => $arr['info']['name'],
                'sex' => $arr['info']['sex'],
                'id_card_num' => $arr['info']['sfz'],
                'tel' => $arr['info']['tel'],
                'openid' => $arr['openid'],
                'status'=>1
            ]);
            if($i){
                $result['status']=true;
                $result['msg']='创建成功';
            }else{
                $result['status']=false;
                $result['msg']='操作失败';
            }
        }
        return $result;
    }
}
