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

106 lines
2.5 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
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::$_ISREST[$value]) ? self::$_ISREST[$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. * @param int $id
  53. * @param string $field
  54. * @return string
  55. */
  56. public static function getStoreInfo($id,$field = '*')
  57. {
  58. return self::select($field)->find($id);
  59. }
  60. /**
  61. * 获取店铺数组
  62. * id为键,name为值
  63. * @return array
  64. */
  65. public static function getStoreArray($where = [], $options = [])
  66. {
  67. $model = self::select('id','name')
  68. ->where('status',2)
  69. ->whereNull('deleted_at');
  70. if(count($where) > 0){
  71. $model->where($where);
  72. }
  73. $list = $model->get();
  74. $array = [];
  75. if(count($list) > 0){
  76. foreach ($list as $value) {
  77. $array[$value->id] = $value->name;
  78. }
  79. }
  80. return $array;
  81. }
  82. // 处理图片
  83. public function imageUrl($value)
  84. {
  85. if(strripos($value,"http") === false){
  86. return config('filesystems.disks.oss.img_host').'/'.$value;
  87. }else{
  88. return $value;
  89. }
  90. }
  91. }