Commit d9fdb78d by wulei@ldy.com

fix

1 parent 689f8ed4
......@@ -7,43 +7,41 @@ use Illuminate\Support\Arr;
class ColumnExts
{
public static function extend()
{
Column::extend('fen2yuan', function ($value) {
return fen2yuan($value);
});
static $extends = [
'fen2yuan' => function ($value) {
return \bcdiv($value, 100, 2);
},
'unit' => function($value, $unit, $left = true) {
Column::extend('unit', function ($value, $unit, $left = true) {
if (\is_callable($unit)) {
$unit = \call_user_func($unit, $this);
}
return $left ? ($unit . $value) : ($value . $unit);
},
'multiline' => function($value, ...$keys) {
return $value . '<br/>' . \implode('<br/>', \array_map(function($key) {
});
Column::extend('multiline', function ($value, ...$keys) {
return $value . '<br/>' . \implode('<br/>', \array_map(function ($key) {
return Arr::get($this, $key, '');
}, $keys));
},
'concat' => function($value, $keys, $separator = "") {
return $value . $separator . \implode($separator, \array_map(function($key) {
});
Column::extend('concat', function ($value, $keys, $separator = "") {
return $value . $separator . \implode($separator, \array_map(function ($key) {
return Arr::get($this, $key, '');
}, (array) $keys));
},
'ellipses' => function($value, $length = 5, $symbol = '...') {
});
Column::extend('ellipses', function ($value, $length = 5, $symbol = '...') {
$new = \mb_substr($value, 0, $length);
if (\mb_strlen($value) > $length) {
$new .= $symbol;
}
return "<span title={$value}>{$new}</span>";
},
'minute2hour' => function($value) {
return \intval($value/60) . '小时' . ($value % 60) . '分钟';
},
];
});
public static function extend()
{
foreach (static::$extends as $name => $disaplayer) {
Column::extend($name, $disaplayer);
}
Column::extend('minute2hour', function ($value) {
return \minute2hour($value);
});
}
}
\ No newline at end of file
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
/**
* Class Resource.
*/
class Resource extends JsonResource
{
protected $only = [];
protected $except = [];
public function __construct($resource, $only = [], $except = [])
{
parent::__construct($resource);
$resource->loadMissing(self::getRequestIncludes());
$this->only = $only;
$this->except = $except;
}
public static function collection($resource)
{
$resource->loadMissing(self::getRequestIncludes());
$collection = parent::collection($resource);
if ($resource instanceof \Illuminate\Pagination\LengthAwarePaginator) {
return new JsonResource([
'info' => $resource->items(),
'count_num' => $resource->total(),
'current_page' => $resource->currentPage(),
'total_pages' => $resource->lastPage(),
]);
}
return $collection;
}
public static function getRequestIncludes()
{
$request = request();
if ($request->has('include')) {
return \array_map('trim', \explode(',', trim($request->get('include'), ',')));
}
return [];
}
public function toArray($request)
{
if ($this->only) {
$data = $this->resource->only($this->only);
} else {
$data = $this->resource->toArray();
}
return Arr::except($data, $this->except);
}
}
......@@ -5,7 +5,9 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model as EloquentModel;
/**
* @method static Illuminate\Database\Eloquent\Builder|Illuminate\Database\Query\Builder where($column, $operator = null, $value = null, $boolean = 'and')
* @method static static|\Illuminate\Database\Eloquent\Builder|Illuminate\Database\Query\Builder where($column, $operator = null, $value = null, $boolean = 'and')
* @method static static|\Illuminate\Database\Eloquent\Builder|Illuminate\Database\Query\Builder whereIn($column, array $values)
* @method static static|\Illuminate\Database\Eloquent\Builder|Illuminate\Database\Query\Builder filter($data, $filterClass = null)
* @method static \Illuminate\Database\Eloquent\Collection|static[]|static|null find($id, $columns = ['*'])
* @method static \Illuminate\Database\Eloquent\Collection|static[]|static|null findOrFail($id, $columns = ['*'])
* @method static \Illuminate\Database\Eloquent\Collection|static[]|static|null findMany($ids, $columns = ['*'])
......@@ -21,4 +23,8 @@ abstract class Model extends EloquentModel
parent::__construct($attributes);
}
protected function serializeDate(\DateTimeInterface $date)
{
return $date->format($this->getDateFormat());
}
}
\ No newline at end of file
<?php
function fen2yuan($value)
{
return bcdiv($value, 100, 2);
}
function minute2hour($value)
{
return intval($value / 60) . '小时' . ($value % 60) . '分钟';
}
......@@ -25,6 +25,9 @@
"phpunit/phpunit": "^9.5.10"
},
"autoload": {
"files": [
"app\\Supports\\helper.php"
],
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!