链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.5 KiB

5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Models;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\Model;
  5. class LanzuServiceSpeaker extends Model
  6. {
  7. use HasDateTimeFormatter;
  8. protected $table = 'lanzu_service_speakers';
  9. protected $dateFormat = 'U';
  10. public function store(){
  11. return $this->hasOne('\App\Models\v3\Store','id','store_id');
  12. }
  13. public static $_STATE = [ 0=>'离线', 1=>'在线'];
  14. public static $_IS_BIND = [ 0=>'未绑定', 1=>'已绑定'];
  15. /* 添加转换字段 */
  16. protected $appends = [
  17. 'created_at_text',
  18. 'updated_at_text',
  19. 'bind_time_text',
  20. 'is_bind_text',
  21. 'state_text'
  22. ];
  23. public function getStateTextAttribute()
  24. {
  25. $value = $this->status;
  26. return isset(self::$_STATE[$value])?self::$_STATE[$value]:'';
  27. }
  28. public function getIsBindTextAttribute()
  29. {
  30. $value = $this->is_bind;
  31. return isset(self::$_IS_BIND[$value])?self::$_IS_BIND[$value]:'';
  32. }
  33. public function getCreatedAtTextAttribute()
  34. {
  35. $value = $this->created_at;
  36. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  37. }
  38. public function getUpdatedAtTextAttribute()
  39. {
  40. $value = $this->updated_at;
  41. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  42. }
  43. public function getBindTimeTextAttribute()
  44. {
  45. $value = $this->bind_time;
  46. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  47. }
  48. }