Prediction.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Builder;
  4. use Illuminate\Foundation\Auth\User as Authenticatable;
  5. use Illuminate\Notifications\Notifiable;
  6. use Laravel\Sanctum\HasApiTokens;
  7. /**
  8. * Admin
  9. * @mixin Builder
  10. * @method static Builder|static where($column, $operator = null, $value = null, $boolean = 'and')
  11. */
  12. class Prediction extends Authenticatable
  13. {
  14. use HasApiTokens, Notifiable;
  15. protected $table = 'prediction';
  16. protected $hidden = ['created_at'];
  17. protected $fillable = ['issue_no', 'size', 'odd_or_even', 'is_valid', 'winning_numbers'];
  18. //预测
  19. static function prediction($issueNo)
  20. {
  21. $size = mt_rand(0, 1);
  22. $oddOrEven = mt_rand(0, 1);
  23. return static::create([
  24. 'issue_no' => $issueNo,
  25. 'size' => $size,
  26. 'odd_or_even' => $oddOrEven
  27. ]);
  28. }
  29. //预测结果
  30. static function result($issueNo, $size, $oddOrEven, $winningNumbers)
  31. {
  32. $data = static::where('issue_no', $issueNo)->first();
  33. if (!$data) $data = static::prediction($issueNo);
  34. $size = $size == '大' ? 1 : 0;
  35. $oddOrEven = $oddOrEven == '双' ? 1 : 0;
  36. $data->is_valid = 0;
  37. if ($data->size == $size || $data->odd_or_even == $oddOrEven) {
  38. $data->is_valid = 1;
  39. }
  40. $data->winning_numbers = $winningNumbers;
  41. $data->save();
  42. }
  43. function getWinningNumbersAttribute($value)
  44. {
  45. if (!empty($value)) {
  46. $value = explode(',', $value);
  47. $value = array_map('intval', $value);
  48. $value[] = array_sum($value);
  49. return $value;
  50. }
  51. return [];
  52. }
  53. }