UserPhoneDetail.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Support\Facades\Log;
  4. class UserPhoneDetail extends Model
  5. {
  6. protected $table = 'user_phone_details';
  7. protected $fillable = ['brand', 'model', 'system', 'platform', 'version', 'SDKVersion', 'locationEnabled', 'locationAuthorized', 'user_id', 'detail'];
  8. public function user()
  9. {
  10. return $this->belongsTo(User::class);
  11. }
  12. public static function Log(array $arr, int $user_id)
  13. {
  14. $data = [];
  15. foreach ($arr as $v) {
  16. $data[$v->type] = $v->value ?? 0;
  17. if ($v->type === 'locationEnabled') {
  18. if ($v->value == '开') {
  19. $value = 1;
  20. } else {
  21. $value = 0;
  22. }
  23. $data[$v->type] = $value;
  24. }
  25. if ($v->type === 'locationAuthorized') {
  26. if ($v->value == '已授权') {
  27. $value = 1;
  28. } else {
  29. $value = 0;
  30. }
  31. $data[$v->type] = $value;
  32. }
  33. }
  34. $data['user_id'] = $user_id;
  35. $data['detail'] = json_encode($arr);
  36. self::query()->updateOrCreate(['user_id' => $user_id], $data);
  37. }
  38. }