Browse Source

流水

master
lemon 4 years ago
parent
commit
e5337f46d2
  1. 29
      app/Listeners/SupplierEventSubscriber.php
  2. 16
      app/Models/DepositLog.php
  3. 11
      app/Traits/StatementTraits.php
  4. 35
      database/migrations/2021_09_17_142758_create_deposit_log_table.php

29
app/Listeners/SupplierEventSubscriber.php

@ -3,6 +3,8 @@
namespace App\Listeners;
use App\Events\DepositUpdate;
use App\Models\DepositLog;
use App\Traits\StatementTraits;
use Illuminate\Support\Facades\Log;
class SupplierEventSubscriber
@ -10,7 +12,32 @@ class SupplierEventSubscriber
public function onSupplierUpdated($event)
{
//处理流水事务
$supplier = $event->supplier;
//如果交易金有变动
if ($supplier->isDirty('deposit_normal')) {
DepositLog::query()->create([
'price' => bcsub($supplier->deposit_normal,$supplier->getOriginal('deposit_normal')),
'type' => StatementTraits::$deposit[0],
'supplier_id' => $supplier->id
]);
}
if ($supplier->isDirty('deposit_frozen')) {
DepositLog::query()->create([
'price' => bcsub($supplier->deposit_frozen,$supplier->getOriginal('deposit_frozen')),
'type' => StatementTraits::$deposit[1],
'supplier_id' => $supplier->id
]);
}
if ($supplier->isDirty('deposit_used')) {
DepositLog::query()->create([
'price' => bcsub($supplier->deposit_used,$supplier->getOriginal('deposit_used')),
'type' => StatementTraits::$deposit[2],
'supplier_id' => $supplier->id
]);
}
}
/**

16
app/Models/DepositLog.php

@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
class DepositLog extends Model
{
use HasDateTimeFormatter;
use SoftDeletes;
protected $table = 'deposit_log';
protected $guarded = ['id']; //不允许编辑的字段
}

11
app/Traits/StatementTraits.php

@ -15,4 +15,15 @@ trait StatementTraits
'App\Models\Withdrawal' => '提现',
];
public static $deposit = [
1,
2,
3,
];
public static $depositText = [
1 => '正常',
2 => '冻结',
3 => '消费'
];
}

35
database/migrations/2021_09_17_142758_create_deposit_log_table.php

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateDepositLogTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('deposit_log', function (Blueprint $table) {
$table->id();
$table->decimal('price',10,2)->default(0)->comment('变更价格');
$table->bigInteger('supplier_id')->default(0)->index()->comment('供应商id');
$table->tinyInteger('type')->default(1)->comment('类型 1正常 2 冻结 3消费');
$table->timestamps();
});
\Illuminate\Support\Facades\DB::statement("alter table deposit_log comment '交易金流水表'");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('deposit_log');
}
}
Loading…
Cancel
Save