2026_08_30_120000_create_operation_configuration_tables.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Schema;
  6. return new class extends Migration
  7. {
  8. public function up(): void
  9. {
  10. Schema::create('payment_direct_recharges', function (Blueprint $table) {
  11. $table->id();
  12. $table->string('recharge_code', 64)->unique()->comment('充值ID/前端识别码');
  13. $table->string('name', 100);
  14. $table->decimal('amount', 20, 2);
  15. $table->decimal('fee_rate', 8, 4)->default(0)->comment('手续费百分比');
  16. $table->tinyInteger('status')->default(1)->index();
  17. $table->unsignedBigInteger('operator_id')->nullable();
  18. $table->string('operator_name', 100)->default('');
  19. $table->timestamps();
  20. $table->softDeletes();
  21. });
  22. Schema::create('payment_gateways', function (Blueprint $table) {
  23. $table->id();
  24. $table->string('kind', 16)->index()->comment('deposit/withdraw');
  25. $table->string('currency', 16)->default('RMB');
  26. $table->string('payment_company', 100);
  27. $table->string('merchant_no', 128);
  28. $table->string('payment_method', 64)->default('');
  29. $table->string('channel_code', 64)->default('');
  30. $table->string('channel_name', 100)->default('');
  31. $table->decimal('fee_rate', 8, 4)->default(0);
  32. $table->text('withdrawal_secret')->nullable();
  33. $table->decimal('min_amount', 20, 2)->default(0);
  34. $table->decimal('max_amount', 20, 2)->default(0);
  35. $table->string('level_scope', 64)->default('all');
  36. $table->unsignedInteger('sort')->default(0);
  37. $table->tinyInteger('status')->default(1)->index();
  38. $table->unsignedBigInteger('operator_id')->nullable();
  39. $table->string('operator_name', 100)->default('');
  40. $table->timestamps();
  41. $table->softDeletes();
  42. $table->index(['kind', 'payment_company']);
  43. });
  44. Schema::create('payment_collection_channels', function (Blueprint $table) {
  45. $table->id();
  46. $table->string('kind', 24)->index()->comment('collection_scan/collection_third_party');
  47. $table->string('currency', 16)->default('RMB');
  48. $table->string('provider_name', 100);
  49. $table->string('group_name', 100);
  50. $table->string('collection_method', 64);
  51. $table->string('channel_code', 64);
  52. $table->string('channel_name', 100);
  53. $table->decimal('fee_rate', 8, 4)->default(0);
  54. $table->decimal('min_amount', 20, 2)->default(0);
  55. $table->decimal('max_amount', 20, 2)->default(0);
  56. $table->string('level_scope', 64)->default('all');
  57. $table->unsignedInteger('sort')->default(0);
  58. $table->tinyInteger('status')->default(1)->index();
  59. $table->unsignedBigInteger('operator_id')->nullable();
  60. $table->string('operator_name', 100)->default('');
  61. $table->timestamps();
  62. $table->softDeletes();
  63. });
  64. Schema::create('operation_audits', function (Blueprint $table) {
  65. $table->id();
  66. $table->string('resource_type', 64)->index();
  67. $table->unsignedBigInteger('resource_id')->nullable()->index();
  68. $table->string('action', 32);
  69. $table->json('changes')->nullable();
  70. $table->unsignedBigInteger('operator_id')->nullable();
  71. $table->string('operator_name', 100)->default('');
  72. $table->timestamp('created_at')->useCurrent()->index();
  73. $table->index(['resource_type', 'resource_id', 'created_at'], 'idx_operation_audits_resource');
  74. });
  75. Schema::create('app_settings', function (Blueprint $table) {
  76. $table->id();
  77. $table->tinyInteger('ios_frontend_visible')->default(0);
  78. $table->tinyInteger('android_frontend_visible')->default(0);
  79. $table->unsignedBigInteger('operator_id')->nullable();
  80. $table->string('operator_name', 100)->default('');
  81. $table->timestamps();
  82. });
  83. Schema::create('app_packages', function (Blueprint $table) {
  84. $table->id();
  85. $table->string('platform', 16)->index();
  86. $table->string('version', 50);
  87. $table->string('package_name', 150);
  88. $table->tinyInteger('force_update')->default(0);
  89. $table->string('package_type', 32);
  90. $table->string('download_url', 1000);
  91. $table->text('update_content')->nullable();
  92. $table->tinyInteger('status')->default(1)->index();
  93. $table->unsignedBigInteger('operator_id')->nullable();
  94. $table->string('operator_name', 100)->default('');
  95. $table->timestamps();
  96. $table->softDeletes();
  97. $table->index(['platform', 'version']);
  98. });
  99. Schema::create('app_download_events', function (Blueprint $table) {
  100. $table->id();
  101. $table->string('event_key', 64)->unique()->comment('客户端事件幂等键哈希');
  102. $table->unsignedBigInteger('package_id')->nullable()->index();
  103. $table->string('event_type', 16)->index()->comment('click/open');
  104. $table->string('platform', 16)->index();
  105. $table->string('package_type', 32)->default('');
  106. $table->string('source', 100)->default('direct');
  107. $table->string('download_url', 1000)->default('')->comment('事件发生时下载链接快照');
  108. $table->string('app_version', 50)->default('');
  109. $table->string('device_id_hash', 64)->default('')->index();
  110. $table->string('ip_hash', 64)->default('');
  111. $table->timestamp('occurred_at')->useCurrent()->index();
  112. $table->index(['event_type', 'occurred_at']);
  113. $table->index(['ip_hash', 'occurred_at']);
  114. $table->index(['device_id_hash', 'occurred_at']);
  115. });
  116. Schema::create('app_ios_review_settings', function (Blueprint $table) {
  117. $table->id();
  118. $table->string('platform', 16)->default('ios');
  119. $table->string('store_version', 50)->index();
  120. $table->string('operating_version', 50);
  121. $table->json('review_user_ids')->nullable();
  122. $table->tinyInteger('status')->default(1)->index();
  123. $table->unsignedBigInteger('operator_id')->nullable();
  124. $table->string('operator_name', 100)->default('');
  125. $table->timestamps();
  126. $table->softDeletes();
  127. });
  128. Schema::create('share_settings', function (Blueprint $table) {
  129. $table->id();
  130. $table->tinyInteger('enabled')->default(0);
  131. $table->string('share_domain', 500)->default('');
  132. $table->decimal('valid_member_min_deposit', 20, 2)->default(20);
  133. $table->tinyInteger('benefit_enabled')->default(0);
  134. $table->decimal('non_seller_threshold', 20, 2)->default(200);
  135. $table->decimal('tier_one_rate', 8, 4)->default(4);
  136. $table->decimal('tier_two_rate', 8, 4)->default(6);
  137. $table->unsignedBigInteger('operator_id')->nullable();
  138. $table->string('operator_name', 100)->default('');
  139. $table->timestamps();
  140. });
  141. Schema::create('share_blacklists', function (Blueprint $table) {
  142. $table->id();
  143. $table->unsignedBigInteger('user_id')->index();
  144. $table->string('member_id', 64)->index();
  145. $table->json('blocked_categories');
  146. $table->tinyInteger('status')->default(1)->index();
  147. $table->unsignedBigInteger('operator_id')->nullable();
  148. $table->string('operator_name', 100)->default('');
  149. $table->timestamps();
  150. $table->softDeletes();
  151. $table->unique('user_id');
  152. });
  153. Schema::create('share_commission_records', function (Blueprint $table) {
  154. $table->id();
  155. $table->date('stat_date')->index();
  156. $table->unsignedBigInteger('promoter_user_id')->index();
  157. $table->unsignedBigInteger('invitee_user_id')->nullable()->index();
  158. $table->string('type', 24)->comment('commission/fee_waiver');
  159. $table->string('category', 32)->default('');
  160. $table->decimal('base_amount', 20, 4)->default(0);
  161. $table->decimal('rate', 8, 4)->default(0);
  162. $table->decimal('amount', 20, 4)->default(0);
  163. $table->string('source_type', 64)->default('');
  164. $table->string('source_id', 100)->default('');
  165. $table->tinyInteger('status')->default(1);
  166. $table->timestamps();
  167. $table->index(['promoter_user_id', 'stat_date', 'type'], 'idx_share_commission_promoter');
  168. $table->unique(['source_type', 'source_id', 'type', 'promoter_user_id'], 'uniq_share_commission_source');
  169. });
  170. DB::table('app_settings')->insert([
  171. 'ios_frontend_visible' => 0,
  172. 'android_frontend_visible' => 0,
  173. 'created_at' => now(),
  174. 'updated_at' => now(),
  175. ]);
  176. DB::table('share_settings')->insert([
  177. 'enabled' => 0,
  178. 'share_domain' => '',
  179. 'valid_member_min_deposit' => 20,
  180. 'benefit_enabled' => 0,
  181. 'non_seller_threshold' => 200,
  182. 'tier_one_rate' => 4,
  183. 'tier_two_rate' => 6,
  184. 'created_at' => now(),
  185. 'updated_at' => now(),
  186. ]);
  187. }
  188. public function down(): void
  189. {
  190. foreach ([
  191. 'share_commission_records', 'share_blacklists', 'share_settings',
  192. 'app_ios_review_settings', 'app_download_events', 'app_packages', 'app_settings',
  193. 'operation_audits', 'payment_collection_channels', 'payment_gateways',
  194. 'payment_direct_recharges',
  195. ] as $table) {
  196. Schema::dropIfExists($table);
  197. }
  198. }
  199. };