| 1234567891011121314151617181920212223242526272829303132 |
- <?php
- use Illuminate\Database\Migrations\Migration;
- use Illuminate\Database\Schema\Blueprint;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Schema;
- /** 回水可多次发放:记录已发放金额/打码量;status 2 = 部分发放(当月提前发放后仍在累计)。 */
- return new class extends Migration {
- public function up(): void
- {
- if (!Schema::hasTable('backflow')) return;
- Schema::table('backflow', function (Blueprint $t) {
- if (!Schema::hasColumn('backflow', 'granted_amount')) $t->decimal('granted_amount', 20, 2)->default(0)->comment('已发放金额');
- if (!Schema::hasColumn('backflow', 'granted_need_flow')) $t->decimal('granted_need_flow', 20, 2)->default(0)->comment('已发放部分的打码量');
- });
- // 已发放的历史记录:发放时的金额即为已发放金额
- DB::table('backflow')->where('status', 1)->where('granted_amount', 0)
- ->update(['granted_amount' => DB::raw('amount'), 'granted_need_flow' => DB::raw('COALESCE(need_flow, 0)')]);
- }
- public function down(): void
- {
- if (!Schema::hasTable('backflow')) return;
- DB::table('backflow')->where('status', 2)->update(['status' => 1]);
- Schema::table('backflow', function (Blueprint $t) {
- foreach (['granted_amount', 'granted_need_flow'] as $column) {
- if (Schema::hasColumn('backflow', $column)) $t->dropColumn($column);
- }
- });
- }
- };
|