UserPhoneDetail.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. protected $guarded = [];
  9. public function user()
  10. {
  11. return $this->belongsTo(User::class);
  12. }
  13. public static function Log(array $arr, int $user_id)
  14. {
  15. $data = [];
  16. foreach ($arr as $v) {
  17. $data[$v->type] = $v->value ?? 0;
  18. if ($v->type === 'locationEnabled') {
  19. if ($v->value == '开') {
  20. $value = 1;
  21. } else {
  22. $value = 0;
  23. }
  24. $data[$v->type] = $value;
  25. }
  26. if ($v->type === 'locationAuthorized') {
  27. if ($v->value == '已授权') {
  28. $value = 1;
  29. } else {
  30. $value = 0;
  31. }
  32. $data[$v->type] = $value;
  33. }
  34. }
  35. $data['user_id'] = $user_id;
  36. $data['detail'] = json_encode($arr);
  37. $data['merchant_id'] = merchant_id();
  38. self::updateOrCreate($data);
  39. }
  40. }