34 lines
761 B
Plaintext
34 lines
761 B
Plaintext
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Services\UserFun;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Ledger extends Model
|
|
{
|
|
// 显式指定表名
|
|
protected $table = 'ledger';
|
|
protected $guarded = ['id'];
|
|
|
|
// 时间字段类型自动转为 Carbon 实例
|
|
protected $casts = [
|
|
'date' => 'datetime',
|
|
'amount' => 'decimal:2',
|
|
];
|
|
|
|
public static function AddIncome($data){
|
|
$ledger= new Ledger();
|
|
$ledger->chat_id=$data['chat_id'];
|
|
$ledger->user_id=$data['user_id'];
|
|
$ledger->date=time();
|
|
$ledger->amount=$data['amount'];
|
|
if($ledger->save()){
|
|
return UserFun::success();
|
|
} else {
|
|
return UserFun::error('资料写入失败');
|
|
}
|
|
}
|
|
|
|
}
|