Zhengshu.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Repositories\Models\Dwbs;
  3. use App\Repositories\Models\Model;
  4. class Zhengshu extends Model
  5. {
  6. /**
  7. * @var string
  8. */
  9. protected $table = 'dwbs_zhengshus';
  10. protected $guarded = [];
  11. /**
  12. * The attributes excluded from the model's JSON form.
  13. *
  14. * @var array
  15. */
  16. protected $hidden = [];
  17. protected $casts = [
  18. 'star_settings' => 'json'
  19. ];
  20. public function getBgAttribute($val)
  21. {
  22. if (empty($val)) {
  23. return config('app.url') . '/default/headimg.png';
  24. }
  25. return path_to_url($val);
  26. }
  27. public function setBgAttribute($val)
  28. {
  29. $this->attributes['bg'] = url_to_path($val);
  30. }
  31. public function getCoverAttribute($val)
  32. {
  33. if (empty($val)) {
  34. return config('app.url') . '/default/headimg.png';
  35. }
  36. return path_to_url($val);
  37. }
  38. public function setCoverAttribute($val)
  39. {
  40. $this->attributes['cover'] = url_to_path($val);
  41. }
  42. /**
  43. * 学分获得下一个等级的证书
  44. * @param $xuefen
  45. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  46. */
  47. public static function byXuefenNext($xuefen)
  48. {
  49. $min = self::query()->where('min_xuefen', '<=', $xuefen)->select(['name', 'min_xuefen', 'is_open_star', 'star_settings'])->orderBy('min_xuefen')->first();
  50. if ($min && $min['is_open_star']) {
  51. $star_settings = $min['star_settings'];
  52. foreach ($star_settings as $setting) {
  53. if ($setting['min_xuefen'] > $xuefen) {
  54. return $min;
  55. }
  56. }
  57. }
  58. $max = self::query()->where('min_xuefen', '>', $xuefen)->select(['name', 'min_xuefen'])->orderBy('min_xuefen')->first();
  59. return $max;
  60. }
  61. }