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

99 lines
2.2 KiB

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