Ken před 2 dny
rodič
revize
ea37c319a3

+ 56 - 0
app/Models/PcPrediction.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace App\Models;
+
+class PcPrediction extends BaseModel
+{
+    protected $table = 'pc_prediction';
+    protected $fillable = ['issue_no', 'size', 'odd_or_even', 'is_valid', 'winning_numbers'];
+    const SIZE_BIG = 1;//预测大小:大
+    const SIZE_SMALL = 0;//预测大小:小
+    const ODD = 0;//预测单双:单
+    const EVEN = 1;//预测单双:双
+    const VALID_CORRECT = 1;//预测结果:正确
+    const VALID_ERROR = 0;//预测结果:错误
+
+
+    //预测
+    static function prediction($issueNo): Prediction
+    {
+        $size = mt_rand(Prediction::SIZE_SMALL, Prediction::SIZE_BIG);
+        $oddOrEven = mt_rand(Prediction::ODD, Prediction::EVEN);
+        return static::create([
+            'issue_no' => $issueNo,
+            'size' => $size,
+            'odd_or_even' => $oddOrEven
+        ]);
+    }
+
+    //预测结果
+    static function result($issueNo, $size, $oddOrEven, $winningNumbers): void
+    {
+        $data = static::where('issue_no', $issueNo)->first();
+        if (!$data) $data = static::prediction($issueNo);
+        $size = $size == '大' ? Prediction::SIZE_BIG : Prediction::SIZE_SMALL;
+        $oddOrEven = $oddOrEven == '双' ? Prediction::EVEN : Prediction::ODD;
+        $data->is_valid = Prediction::VALID_ERROR;
+        if ($data->size == $size || $data->odd_or_even == $oddOrEven) {
+            $data->is_valid = Prediction::VALID_CORRECT;
+        }
+        $data->winning_numbers = $winningNumbers;
+        $data->save();
+
+    }
+
+
+    function getWinningNumbersAttribute($value)
+    {
+        if (!empty($value)) {
+            $value = explode(',', $value);
+            $value = array_map('intval', $value);
+            $value[] = array_sum($value);
+            return $value;
+        }
+        return [];
+    }
+}

+ 4 - 0
app/Services/PcIssueService.php

@@ -69,6 +69,7 @@ class PcIssueService extends BaseService
                 $item->status = PcIssue::STATUS_DRAW;
                 $item->save();
                 $awards = IssueService::award(explode(',', $item->winning_numbers));
+//                PcCao::updateData($awards);
                 PcCaoHistory::updateData($awards);
 
 
@@ -93,6 +94,9 @@ class PcIssueService extends BaseService
                 'start_time' => $issue->end_time,
                 'end_time' => date('Y-m-d H:i:s', $end_time),
             ]);
+            PcPrediction::prediction($new_str);
+
+
             if (strtotime($issue->end_time) <= $now) {
                 static::createIssueNo();
             }

+ 38 - 0
database/migrations/2025_12_09_095546_create__pc_prediction.php

@@ -0,0 +1,38 @@
+<?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('pc_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('_pc_prediction');
+    }
+};