<?php

namespace App\Services\User;

use App\Services\Service;
use App\Models\User\OpenidUserModel;

class OpenidUserService extends Service
{
    /**
     * 更新用户信息
     * @param  string  $openid
     * @param  array  $data
     */
    public function update(string $openid, array $data)
    {
        if (array_key_exists('location', $data) && is_array($data['location'])) {
            $data['location'] = "";
        }
        OpenidUserModel::updateOrCreate(['openid' => $openid], $data);
    }

    public function get(string $openid)
    {
        $data = OpenidUserModel::firstOrCreate(['openid' => $openid], ['openid' => $openid, 'created_at' => time()]);

        return $data;
    }
}
