You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Code Model
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
use App\Utils\Tools;
|
|
|
|
|
|
|
|
|
|
class Code extends Model
|
|
|
|
|
{
|
|
|
|
|
protected $connection = "default";
|
|
|
|
|
protected $table = "code";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
|
{
|
|
|
|
|
return User::where("id", $this->attributes['userid'])->first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getDisplayCodeAttribute()
|
|
|
|
|
{
|
|
|
|
|
$value = (string) ($this->attributes['code'] ?? '');
|
|
|
|
|
$type = (int) ($this->attributes['type'] ?? 0);
|
|
|
|
|
if (in_array($type, [10005, 10007], true) && preg_match('/^[A-Za-z0-9]{8}$/', $value) !== 1) {
|
|
|
|
|
return strtoupper(substr(hash('sha256', 'recharge-display:' . $value), 0, 8));
|
|
|
|
|
}
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getUsedAtTimestampAttribute()
|
|
|
|
|
{
|
|
|
|
|
$timestamp = strtotime((string) ($this->attributes['usedatetime'] ?? ''));
|
|
|
|
|
return $timestamp === false ? 0 : $timestamp;
|
|
|
|
|
}
|
|
|
|
|
}
|