链街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.

112 lines
2.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Models\v3;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Illuminate\Database\Eloquent\Model;
  6. class Store extends Model
  7. {
  8. use HasDateTimeFormatter;
  9. use SoftDeletes;
  10. protected $table = 'lanzu_store';
  11. protected $dateFormat = 'U';
  12. protected $appends = [
  13. 'logo_url',
  14. 'is_rest_text',
  15. 'is_open_text'
  16. ];
  17. public static $_isRest= ['否','是'];
  18. public static $_isOpen = ['关闭','开启'];
  19. public function getLogoUrlAttribute($value)
  20. {
  21. $value = $value ? $value : $this->logo;
  22. return $this->imageUrl($value);
  23. }
  24. public function getIsRestTextAttribute($value)
  25. {
  26. $value = $value ? $value : $this->is_rest;
  27. return isset(self::$_onRest[$value]) ? self::$_onRest[$value] : '';
  28. }
  29. public function getIsOpenTextAttribute($value)
  30. {
  31. $value = $value ? $value : $this->is_iopen;
  32. return isset(self::$_isOpen[$value]) ? self::$_isOpen[$value] : '';
  33. }
  34. /**
  35. * 获取商家环境图片
  36. * @param $value $this->environment
  37. * @return array
  38. */
  39. public function getEnvironmentAttribute($value)
  40. {
  41. $value = $value ? $value : $this->environmant;
  42. return $value ? explode(',',$value) : [];
  43. }
  44. public function setEnvironmentAttribute($value)
  45. {
  46. $this->attributes['environment'] = implode(',',$value);
  47. }
  48. /**
  49. * 是否开启店铺
  50. */
  51. public function getIsOpenAttribute($value)
  52. {
  53. $value = $value ? $value : '';
  54. return $value ? explode(',',$value) : [];
  55. }
  56. public function setIsOpenAttribute($value)
  57. {
  58. $this->attributes['is_open'] = 1;
  59. }
  60. /**
  61. * 获取单个店铺信息
  62. * @param int $id
  63. * @param string $field
  64. * @return string
  65. */
  66. public static function getStoreInfo($id,$field = '*')
  67. {
  68. return self::select($field)->find($id);
  69. }
  70. /**
  71. * 获取店铺数组
  72. * id为键,name为值
  73. * @return array
  74. */
  75. public static function getStoreArray()
  76. {
  77. $list = self::select('id','name')
  78. ->where('status',2)
  79. ->whereNull('deleted_at')
  80. ->get();
  81. $array = [];
  82. if(count($list) > 0){
  83. foreach ($list as $value) {
  84. $array[$value->id] = $value->name;
  85. }
  86. }
  87. return $array;
  88. }
  89. // 处理图片
  90. public function imageUrl($value)
  91. {
  92. if(strripos($value,"http") === false){
  93. return env('OSS_IMG_HOST').'/'.$value;
  94. }else{
  95. return $value;
  96. }
  97. }
  98. }