Ken 1 неделя назад
Родитель
Сommit
294f1bfac4

+ 63 - 0
app/Models/Prediction.php

@@ -0,0 +1,63 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Foundation\Auth\User as Authenticatable;
+use Illuminate\Notifications\Notifiable;
+use Laravel\Sanctum\HasApiTokens;
+
+/**
+ * Admin
+ * @mixin Builder
+ * @method static Builder|static where($column, $operator = null, $value = null, $boolean = 'and')
+ */
+class Prediction extends Authenticatable
+{
+    use HasApiTokens, Notifiable;
+    protected $table = 'prediction';
+    protected $hidden = ['created_at', 'updated_at'];
+    protected $fillable = ['issue_no', 'size', 'odd_or_even', 'is_valid', 'winning_numbers'];
+
+
+    //预测
+    static function prediction($issueNo)
+    {
+        $size = mt_rand(0, 1);
+        $oddOrEven = mt_rand(0, 1);
+        return static::create([
+            'issue_no' => $issueNo,
+            'size' => $size,
+            'odd_or_even' => $oddOrEven
+        ]);
+    }
+
+    //预测结果
+    static function result($issueNo, $size, $oddOrEven, $winningNumbers)
+    {
+        $data = static::where('issue_no', $issueNo)->first();
+
+        $size = $size == '大' ? 1 : 0;
+        $oddOrEven = $oddOrEven == '双' ? 1 : 0;
+        $data->is_valid = 0;
+        if ($data->size == $size && $data->odd_or_even == $oddOrEven) {
+            $data->is_valid = 1;
+        }
+        $data->winning_numbers = $winningNumbers;
+        $data->save();
+    }
+
+
+    function getWinningNumbersAttribute($value)
+    {
+        if (!empty($this->winning_numbers)) {
+            $value = explode(',', $value);
+            $value = array_map('intval', $value);
+            $value[] = array_sum($value);
+            return $value;
+        }
+        return [];
+    }
+
+
+}

+ 37 - 0
database/migrations/2025_11_07_140042_create_prediction.php

@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration {
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('prediction', function (Blueprint $table) {
+            $table->id();
+            $table->string('issue_no', 50)->unique()->comment('期号');
+            $table->tinyInteger('size')->comment('预测大小:0小,1大');
+            $table->tinyInteger('odd_or_even')->comment('预测单双:0单,1双');
+            $table->tinyInteger('is_valid')->nullable()->comment("结果:0错误,1正确");
+            $table->string('winning_numbers')->nullable()->comment('开奖号码');
+
+
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('prediction');
+    }
+};