12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Models;
- use Illuminate\Support\Facades\Log;
- class UserPhoneDetail extends Model
- {
- protected $table = 'user_phone_details';
- protected $fillable = ['brand', 'model', 'system', 'platform', 'version', 'SDKVersion', 'locationEnabled', 'locationAuthorized', 'user_id', 'detail'];
- public function user()
- {
- return $this->belongsTo(User::class);
- }
- public static function Log(array $arr, int $user_id)
- {
- $data = [];
- foreach ($arr as $v) {
- $data[$v->type] = $v->value ?? 0;
- if ($v->type === 'locationEnabled') {
- if ($v->value == '开') {
- $value = 1;
- } else {
- $value = 0;
- }
- $data[$v->type] = $value;
- }
- if ($v->type === 'locationAuthorized') {
- if ($v->value == '已授权') {
- $value = 1;
- } else {
- $value = 0;
- }
- $data[$v->type] = $value;
- }
- }
- $data['user_id'] = $user_id;
- $data['detail'] = json_encode($arr);
- self::query()->updateOrCreate(['user_id' => $user_id], $data);
- }
- }
|