UserPhoneDetail.php 1.2 KB

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