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

96 lines
2.1 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 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. ];
  15. public function getLogoUrlAttribute($value)
  16. {
  17. $value = $value ? $value : $this->logo;
  18. return $this->imageUrl($value);
  19. }
  20. /**
  21. * 获取商家环境图片
  22. * @param $value $this->environment
  23. * @return array
  24. */
  25. public function getEnvironmentAttribute($value)
  26. {
  27. $value = $value ? $value : $this->environmant;
  28. return $value ? explode(',',$value) : [];
  29. }
  30. public function setEnvironmentAttribute($value)
  31. {
  32. $this->attributes['environment'] = implode(',',$value);
  33. }
  34. /**
  35. * 是否开启店铺
  36. */
  37. public function getIsOpenAttribute($value)
  38. {
  39. $value = $value ? $value : '';
  40. return $value ? explode(',',$value) : [];
  41. }
  42. public function setIsOpenAttribute($value)
  43. {
  44. $this->attributes['is_open'] = 1;
  45. }
  46. /**
  47. * 获取单个店铺信息
  48. * @param int $id
  49. * @param string $field
  50. * @return string
  51. */
  52. public static function getStoreInfo($id,$field = '*')
  53. {
  54. return self::select($field)->find($id);
  55. }
  56. /**
  57. * 获取店铺数组
  58. * id为键,name为值
  59. * @return array
  60. */
  61. public static function getStoreArray()
  62. {
  63. $list = self::select('id','name')
  64. ->where('status',2)
  65. ->whereNull('deleted_at')
  66. ->get();
  67. $array = [];
  68. if(count($list) > 0){
  69. foreach ($list as $value) {
  70. $array[$value->id] = $value->name;
  71. }
  72. }
  73. return $array;
  74. }
  75. // 处理图片
  76. public function imageUrl($value)
  77. {
  78. if(strripos($value,"http") === false){
  79. return env('OSS_IMG_HOST').'/'.$value;
  80. }else{
  81. return $value;
  82. }
  83. }
  84. }