67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use RuLong\Identity\Models\IdentityPoint;
|
|
|
|
class ProfitLog extends Model
|
|
{
|
|
protected $dates = [
|
|
'end_at',
|
|
];
|
|
|
|
public function getStatusTextAttribute()
|
|
{
|
|
switch ($this->status) {
|
|
case 0:
|
|
return '尚未执行';
|
|
break;
|
|
case 1:
|
|
return '已经执行';
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function portion($id, $user_id = 0)
|
|
{
|
|
return IdentityPoint::where('identity_id', $id)
|
|
->when($user_id, function ($q) use ($user_id) {
|
|
$q->where('user_id', $user_id);
|
|
})
|
|
->where('created_at', '<', $this->end_at)->sum('point');
|
|
}
|
|
|
|
public static function getnow()
|
|
{
|
|
$time = Carbon::today()->toDateTimeString();
|
|
$info = self::where('created_at', $time)->first();
|
|
if (!$info) {
|
|
$info = self::create([
|
|
'price' => 0,
|
|
'created_at' => $time,
|
|
'end_at' => Carbon::today()->addSecond(86399)->toDateTimeString(),
|
|
'status' => 0,
|
|
]);
|
|
}
|
|
return $info;
|
|
}
|
|
|
|
public static function addPrfit($price = 0)
|
|
{
|
|
$time = Carbon::today()->toDateTimeString();
|
|
$info = self::where('created_at', $time)->first();
|
|
if ($info) {
|
|
$info->price += $price;
|
|
$info->save();
|
|
} else {
|
|
self::create([
|
|
'price' => $price,
|
|
'created_at' => $time,
|
|
'end_at' => Carbon::today()->addSecond(86399)->toDateTimeString(),
|
|
'status' => 0,
|
|
]);
|
|
}
|
|
}
|
|
}
|