123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Repositories\Models\Dwbs;
- use App\Repositories\Models\Model;
- class Zhengshu extends Model
- {
- /**
- * @var string
- */
- protected $table = 'dwbs_zhengshus';
- protected $guarded = [];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = [];
- protected $casts = [
- 'star_settings' => 'json'
- ];
- public function getBgAttribute($val)
- {
- if (empty($val)) {
- return config('app.url') . '/default/headimg.png';
- }
- return path_to_url($val);
- }
- public function setBgAttribute($val)
- {
- $this->attributes['bg'] = url_to_path($val);
- }
- public function getCoverAttribute($val)
- {
- if (empty($val)) {
- return config('app.url') . '/default/headimg.png';
- }
- return path_to_url($val);
- }
- public function setCoverAttribute($val)
- {
- $this->attributes['cover'] = url_to_path($val);
- }
- /**
- * 学分获得下一个等级的证书
- * @param $xuefen
- * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
- */
- public static function byXuefenNext($xuefen)
- {
- $min = self::query()->where('min_xuefen', '<=', $xuefen)->select(['name', 'min_xuefen', 'is_open_star', 'star_settings'])->orderBy('min_xuefen')->first();
- if ($min && $min['is_open_star']) {
- $star_settings = $min['star_settings'];
- foreach ($star_settings as $setting) {
- if ($setting['min_xuefen'] > $xuefen) {
- return $min;
- }
- }
- }
- $max = self::query()->where('min_xuefen', '>', $xuefen)->select(['name', 'min_xuefen'])->orderBy('min_xuefen')->first();
- return $max;
- }
- }
|