更新功能
This commit is contained in:
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace Modules\Account\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\BaseModel;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Bill extends Model
|
||||
class Bill extends BaseModel
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
@@ -17,6 +17,7 @@ class Bill extends Model
|
||||
'type',
|
||||
'amount',
|
||||
'category',
|
||||
'payment_method',
|
||||
'remark',
|
||||
'bill_date'
|
||||
];
|
||||
@@ -25,7 +26,8 @@ class Bill extends Model
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'bill_date' => 'date',
|
||||
'date' => 'datetime:Y-m-d',
|
||||
'bill_date' => 'datetime:Y-m-d',
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
'deleted_at' => 'datetime:Y-m-d H:i:s',
|
||||
|
||||
@@ -99,10 +99,11 @@ class BillService
|
||||
'amount' => (float)$bill->amount,
|
||||
'category' => $bill->category,
|
||||
'category_id' => $this->getCategoryId($bill->category, $bill->type),
|
||||
'payment_method' => $bill->payment_method,
|
||||
'remark' => $bill->remark,
|
||||
'date' => $bill->bill_date,
|
||||
'bill_date' => $bill->bill_date,
|
||||
'created_at' => $bill->created_at->format('Y-m-d H:i:s'),
|
||||
'created_at' => $bill->created_at,
|
||||
'user' => $bill->user,
|
||||
'family' => $bill->family
|
||||
];
|
||||
@@ -162,6 +163,7 @@ class BillService
|
||||
'type' => 'required|in:income,expense',
|
||||
'amount' => 'required|numeric|min:0.01',
|
||||
'category_id' => 'required|integer',
|
||||
'payment_method' => 'nullable|string|in:微信,支付宝,银行卡,现金,其他',
|
||||
'remark' => 'nullable|string|max:255',
|
||||
'date' => 'required|date',
|
||||
'family_id' => 'nullable|integer|exists:account_families,id'
|
||||
@@ -241,6 +243,7 @@ class BillService
|
||||
'type' => 'required|in:income,expense',
|
||||
'amount' => 'required|numeric|min:0.01',
|
||||
'category_id' => 'required|integer',
|
||||
'payment_method' => 'nullable|string|in:微信,支付宝,银行卡,现金,其他',
|
||||
'remark' => 'nullable|string|max:255',
|
||||
'date' => 'required|date',
|
||||
'family_id' => 'nullable|integer|exists:account_families,id'
|
||||
@@ -303,19 +306,8 @@ class BillService
|
||||
}
|
||||
|
||||
// 转换数据格式以匹配前端
|
||||
return [
|
||||
'id' => $bill->id,
|
||||
'type' => $bill->type,
|
||||
'amount' => (float)$bill->amount,
|
||||
'category' => $bill->category,
|
||||
'category_id' => $this->getCategoryId($bill->category, $bill->type),
|
||||
'remark' => $bill->remark,
|
||||
'date' => $bill->bill_date,
|
||||
'bill_date' => $bill->bill_date,
|
||||
'created_at' => $bill->created_at->format('Y-m-d H:i:s'),
|
||||
'user' => $bill->user,
|
||||
'family' => $bill->family
|
||||
];
|
||||
$bill->category_id = $this->getCategoryId($bill->category, $bill->type);
|
||||
return $bill;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('account_bills', function (Blueprint $table) {
|
||||
$table->string('payment_method', 20)->nullable()->after('category')->comment('支付方式:微信、支付宝、银行卡、现金、其他');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('account_bills', function (Blueprint $table) {
|
||||
$table->dropColumn('payment_method');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -14,7 +14,7 @@ use Modules\Account\Controllers\Api\StatisticsController;
|
||||
|
|
||||
*/
|
||||
|
||||
Route::middleware(['auth:api'])->group(function () {
|
||||
Route::name('account.')->prefix('account')->middleware(['auth.check:api'])->group(function () {
|
||||
// 账单路由
|
||||
Route::prefix('bill')->group(function () {
|
||||
Route::get('list', [BillController::class, 'index']);
|
||||
|
||||
Reference in New Issue
Block a user