0
0

更新代码

This commit is contained in:
2020-08-04 10:09:42 +08:00
parent 6118b5b63b
commit c2ac5d964e
478 changed files with 34410 additions and 0 deletions

66
app/Models/ProfitLog.php Normal file
View File

@@ -0,0 +1,66 @@
<?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,
]);
}
}
}