OpenidUserService.php 707 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Services\User;
  3. use App\Services\Service;
  4. use App\Models\User\OpenidUserModel;
  5. class OpenidUserService extends Service
  6. {
  7. /**
  8. * 更新用户信息
  9. * @param string $openid
  10. * @param array $data
  11. */
  12. public function update(string $openid, array $data)
  13. {
  14. if (array_key_exists('location', $data) && is_array($data['location'])) {
  15. $data['location'] = "";
  16. }
  17. OpenidUserModel::updateOrCreate(['openid' => $openid], $data);
  18. }
  19. public function get(string $openid)
  20. {
  21. $data = OpenidUserModel::firstOrCreate(['openid' => $openid], ['openid' => $openid, 'created_at' => time()]);
  22. return $data;
  23. }
  24. }