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

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