Prediction.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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', 'updated_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. $size = $size == '大' ? 1 : 0;
  34. $oddOrEven = $oddOrEven == '双' ? 1 : 0;
  35. $data->is_valid = 0;
  36. if ($data->size == $size && $data->odd_or_even == $oddOrEven) {
  37. $data->is_valid = 1;
  38. }
  39. $data->winning_numbers = $winningNumbers;
  40. $data->save();
  41. }
  42. function getWinningNumbersAttribute($value)
  43. {
  44. if (!empty($this->winning_numbers)) {
  45. $value = explode(',', $value);
  46. $value = array_map('intval', $value);
  47. $value[] = array_sum($value);
  48. return $value;
  49. }
  50. return [];
  51. }
  52. }